001
014
015 package com.liferay.portlet.messageboards.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.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.CalendarUtil;
032 import com.liferay.portal.kernel.util.GetterUtil;
033 import com.liferay.portal.kernel.util.InstanceFactory;
034 import com.liferay.portal.kernel.util.OrderByComparator;
035 import com.liferay.portal.kernel.util.StringBundler;
036 import com.liferay.portal.kernel.util.StringPool;
037 import com.liferay.portal.kernel.util.StringUtil;
038 import com.liferay.portal.model.CacheModel;
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.LockPersistence;
043 import com.liferay.portal.service.persistence.ResourcePersistence;
044 import com.liferay.portal.service.persistence.UserPersistence;
045 import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
046 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047
048 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
049 import com.liferay.portlet.messageboards.NoSuchThreadException;
050 import com.liferay.portlet.messageboards.model.MBThread;
051 import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
052 import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
053 import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
054 import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
055
056 import java.io.Serializable;
057
058 import java.util.ArrayList;
059 import java.util.Collections;
060 import java.util.Date;
061 import java.util.List;
062
063
075 public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
076 implements MBThreadPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
088 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
090 new String[] {
091 Long.class.getName(),
092
093 "java.lang.Integer", "java.lang.Integer",
094 "com.liferay.portal.kernel.util.OrderByComparator"
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
097 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
098 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
100 new String[] { Long.class.getName() },
101 MBThreadModelImpl.GROUPID_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
103 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
105 new String[] { Long.class.getName() });
106 public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
107 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
108 FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
109 new String[] { Long.class.getName() },
110 MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
112 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
114 new String[] { Long.class.getName() });
115 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
116 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
117 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
118 new String[] {
119 Long.class.getName(), Long.class.getName(),
120
121 "java.lang.Integer", "java.lang.Integer",
122 "com.liferay.portal.kernel.util.OrderByComparator"
123 });
124 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
125 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
126 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
127 new String[] { Long.class.getName(), Long.class.getName() },
128 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
129 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK);
130 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
131 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
132 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
133 new String[] { Long.class.getName(), Long.class.getName() });
134 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
135 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
136 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
137 new String[] {
138 Long.class.getName(), Long.class.getName(),
139
140 "java.lang.Integer", "java.lang.Integer",
141 "com.liferay.portal.kernel.util.OrderByComparator"
142 });
143 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC =
144 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
145 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
146 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_NotC",
147 new String[] { Long.class.getName(), Long.class.getName() },
148 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
149 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK);
150 public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
151 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
152 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_NotC",
153 new String[] { Long.class.getName(), Long.class.getName() });
154 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
155 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
156 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
157 new String[] {
158 Long.class.getName(), Integer.class.getName(),
159
160 "java.lang.Integer", "java.lang.Integer",
161 "com.liferay.portal.kernel.util.OrderByComparator"
162 });
163 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
164 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
165 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
166 new String[] { Long.class.getName(), Integer.class.getName() },
167 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
168 MBThreadModelImpl.STATUS_COLUMN_BITMASK);
169 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
170 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
171 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
172 new String[] { Long.class.getName(), Integer.class.getName() });
173 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
174 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
175 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
176 new String[] {
177 Long.class.getName(), Double.class.getName(),
178
179 "java.lang.Integer", "java.lang.Integer",
180 "com.liferay.portal.kernel.util.OrderByComparator"
181 });
182 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
183 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
184 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
185 new String[] { Long.class.getName(), Double.class.getName() },
186 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
187 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
188 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
189 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
190 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
191 new String[] { Long.class.getName(), Double.class.getName() });
192 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
193 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
194 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
195 new String[] {
196 Date.class.getName(), Double.class.getName(),
197
198 "java.lang.Integer", "java.lang.Integer",
199 "com.liferay.portal.kernel.util.OrderByComparator"
200 });
201 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
202 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
203 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
204 new String[] { Date.class.getName(), Double.class.getName() },
205 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
206 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
207 public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
208 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
209 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
210 new String[] { Date.class.getName(), Double.class.getName() });
211 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
212 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
213 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_L",
214 new String[] {
215 Long.class.getName(), Long.class.getName(), Date.class.getName(),
216
217 "java.lang.Integer", "java.lang.Integer",
218 "com.liferay.portal.kernel.util.OrderByComparator"
219 });
220 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
221 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
222 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
223 new String[] {
224 Long.class.getName(), Long.class.getName(), Date.class.getName()
225 },
226 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
227 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
228 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
229 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
230 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
231 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
232 new String[] {
233 Long.class.getName(), Long.class.getName(), Date.class.getName()
234 });
235 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
236 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
237 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
238 new String[] {
239 Long.class.getName(), Long.class.getName(),
240 Integer.class.getName(),
241
242 "java.lang.Integer", "java.lang.Integer",
243 "com.liferay.portal.kernel.util.OrderByComparator"
244 });
245 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
246 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
247 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
248 new String[] {
249 Long.class.getName(), Long.class.getName(),
250 Integer.class.getName()
251 },
252 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
253 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
254 MBThreadModelImpl.STATUS_COLUMN_BITMASK);
255 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
256 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
257 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
258 new String[] {
259 Long.class.getName(), Long.class.getName(),
260 Integer.class.getName()
261 });
262 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
263 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
264 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_S",
265 new String[] {
266 Long.class.getName(), Long.class.getName(),
267 Integer.class.getName(),
268
269 "java.lang.Integer", "java.lang.Integer",
270 "com.liferay.portal.kernel.util.OrderByComparator"
271 });
272 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S =
273 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
274 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
275 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_NotC_S",
276 new String[] {
277 Long.class.getName(), Long.class.getName(),
278 Integer.class.getName()
279 },
280 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
281 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
282 MBThreadModelImpl.STATUS_COLUMN_BITMASK);
283 public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
284 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
285 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_NotC_S",
286 new String[] {
287 Long.class.getName(), Long.class.getName(),
288 Integer.class.getName()
289 });
290 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
291 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
292 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
293 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
294 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
295 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
296 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
297 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
298 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
299
300
305 public void cacheResult(MBThread mbThread) {
306 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
307 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
308
309 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
310 new Object[] { Long.valueOf(mbThread.getRootMessageId()) }, mbThread);
311
312 mbThread.resetOriginalValues();
313 }
314
315
320 public void cacheResult(List<MBThread> mbThreads) {
321 for (MBThread mbThread : mbThreads) {
322 if (EntityCacheUtil.getResult(
323 MBThreadModelImpl.ENTITY_CACHE_ENABLED,
324 MBThreadImpl.class, mbThread.getPrimaryKey()) == null) {
325 cacheResult(mbThread);
326 }
327 else {
328 mbThread.resetOriginalValues();
329 }
330 }
331 }
332
333
340 @Override
341 public void clearCache() {
342 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
343 CacheRegistryUtil.clear(MBThreadImpl.class.getName());
344 }
345
346 EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
347
348 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
349 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
350 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
351 }
352
353
360 @Override
361 public void clearCache(MBThread mbThread) {
362 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
363 MBThreadImpl.class, mbThread.getPrimaryKey());
364
365 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
366 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
367
368 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
369 new Object[] { Long.valueOf(mbThread.getRootMessageId()) });
370 }
371
372
378 public MBThread create(long threadId) {
379 MBThread mbThread = new MBThreadImpl();
380
381 mbThread.setNew(true);
382 mbThread.setPrimaryKey(threadId);
383
384 return mbThread;
385 }
386
387
395 @Override
396 public MBThread remove(Serializable primaryKey)
397 throws NoSuchModelException, SystemException {
398 return remove(((Long)primaryKey).longValue());
399 }
400
401
409 public MBThread remove(long threadId)
410 throws NoSuchThreadException, SystemException {
411 Session session = null;
412
413 try {
414 session = openSession();
415
416 MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
417 Long.valueOf(threadId));
418
419 if (mbThread == null) {
420 if (_log.isWarnEnabled()) {
421 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
422 }
423
424 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
425 threadId);
426 }
427
428 return mbThreadPersistence.remove(mbThread);
429 }
430 catch (NoSuchThreadException nsee) {
431 throw nsee;
432 }
433 catch (Exception e) {
434 throw processException(e);
435 }
436 finally {
437 closeSession(session);
438 }
439 }
440
441
448 @Override
449 public MBThread remove(MBThread mbThread) throws SystemException {
450 return super.remove(mbThread);
451 }
452
453 @Override
454 protected MBThread removeImpl(MBThread mbThread) throws SystemException {
455 mbThread = toUnwrappedModel(mbThread);
456
457 Session session = null;
458
459 try {
460 session = openSession();
461
462 BatchSessionUtil.delete(session, mbThread);
463 }
464 catch (Exception e) {
465 throw processException(e);
466 }
467 finally {
468 closeSession(session);
469 }
470
471 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
472 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
473
474 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
475
476 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
477 new Object[] { Long.valueOf(mbThreadModelImpl.getRootMessageId()) });
478
479 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
480 MBThreadImpl.class, mbThread.getPrimaryKey());
481
482 return mbThread;
483 }
484
485 @Override
486 public MBThread updateImpl(
487 com.liferay.portlet.messageboards.model.MBThread mbThread, boolean merge)
488 throws SystemException {
489 mbThread = toUnwrappedModel(mbThread);
490
491 boolean isNew = mbThread.isNew();
492
493 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
494
495 Session session = null;
496
497 try {
498 session = openSession();
499
500 BatchSessionUtil.update(session, mbThread, merge);
501
502 mbThread.setNew(false);
503 }
504 catch (Exception e) {
505 throw processException(e);
506 }
507 finally {
508 closeSession(session);
509 }
510
511 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
512
513 if (isNew || !MBThreadModelImpl.COLUMN_BITMASK_ENABLED) {
514 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
515 }
516
517 else {
518 if ((mbThreadModelImpl.getColumnBitmask() &
519 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
520 Object[] args = new Object[] {
521 Long.valueOf(mbThreadModelImpl.getOriginalGroupId())
522 };
523
524 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
525 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
526 args);
527
528 args = new Object[] { Long.valueOf(mbThreadModelImpl.getGroupId()) };
529
530 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
531 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
532 args);
533 }
534
535 if ((mbThreadModelImpl.getColumnBitmask() &
536 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
537 Object[] args = new Object[] {
538 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
539 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId())
540 };
541
542 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
543 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
544 args);
545
546 args = new Object[] {
547 Long.valueOf(mbThreadModelImpl.getGroupId()),
548 Long.valueOf(mbThreadModelImpl.getCategoryId())
549 };
550
551 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
552 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
553 args);
554 }
555
556 if ((mbThreadModelImpl.getColumnBitmask() &
557 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC.getColumnBitmask()) != 0) {
558 Object[] args = new Object[] {
559 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
560 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId())
561 };
562
563 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTC, args);
564 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC,
565 args);
566
567 args = new Object[] {
568 Long.valueOf(mbThreadModelImpl.getGroupId()),
569 Long.valueOf(mbThreadModelImpl.getCategoryId())
570 };
571
572 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTC, args);
573 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC,
574 args);
575 }
576
577 if ((mbThreadModelImpl.getColumnBitmask() &
578 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
579 Object[] args = new Object[] {
580 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
581 Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
582 };
583
584 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
585 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
586 args);
587
588 args = new Object[] {
589 Long.valueOf(mbThreadModelImpl.getGroupId()),
590 Integer.valueOf(mbThreadModelImpl.getStatus())
591 };
592
593 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
594 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
595 args);
596 }
597
598 if ((mbThreadModelImpl.getColumnBitmask() &
599 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
600 Object[] args = new Object[] {
601 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
602 Double.valueOf(mbThreadModelImpl.getOriginalPriority())
603 };
604
605 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
606 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
607 args);
608
609 args = new Object[] {
610 Long.valueOf(mbThreadModelImpl.getCategoryId()),
611 Double.valueOf(mbThreadModelImpl.getPriority())
612 };
613
614 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
615 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
616 args);
617 }
618
619 if ((mbThreadModelImpl.getColumnBitmask() &
620 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
621 Object[] args = new Object[] {
622 mbThreadModelImpl.getOriginalLastPostDate(),
623 Double.valueOf(mbThreadModelImpl.getOriginalPriority())
624 };
625
626 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
627 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
628 args);
629
630 args = new Object[] {
631 mbThreadModelImpl.getLastPostDate(),
632 Double.valueOf(mbThreadModelImpl.getPriority())
633 };
634
635 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
636 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
637 args);
638 }
639
640 if ((mbThreadModelImpl.getColumnBitmask() &
641 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
642 Object[] args = new Object[] {
643 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
644 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
645
646 mbThreadModelImpl.getOriginalLastPostDate()
647 };
648
649 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
650 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
651 args);
652
653 args = new Object[] {
654 Long.valueOf(mbThreadModelImpl.getGroupId()),
655 Long.valueOf(mbThreadModelImpl.getCategoryId()),
656
657 mbThreadModelImpl.getLastPostDate()
658 };
659
660 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
661 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
662 args);
663 }
664
665 if ((mbThreadModelImpl.getColumnBitmask() &
666 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
667 Object[] args = new Object[] {
668 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
669 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
670 Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
671 };
672
673 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
674 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
675 args);
676
677 args = new Object[] {
678 Long.valueOf(mbThreadModelImpl.getGroupId()),
679 Long.valueOf(mbThreadModelImpl.getCategoryId()),
680 Integer.valueOf(mbThreadModelImpl.getStatus())
681 };
682
683 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
684 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
685 args);
686 }
687
688 if ((mbThreadModelImpl.getColumnBitmask() &
689 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S.getColumnBitmask()) != 0) {
690 Object[] args = new Object[] {
691 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
692 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
693 Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
694 };
695
696 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTC_S, args);
697 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S,
698 args);
699
700 args = new Object[] {
701 Long.valueOf(mbThreadModelImpl.getGroupId()),
702 Long.valueOf(mbThreadModelImpl.getCategoryId()),
703 Integer.valueOf(mbThreadModelImpl.getStatus())
704 };
705
706 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTC_S, args);
707 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S,
708 args);
709 }
710 }
711
712 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
713 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
714
715 if (isNew) {
716 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
717 new Object[] { Long.valueOf(mbThread.getRootMessageId()) },
718 mbThread);
719 }
720 else {
721 if ((mbThreadModelImpl.getColumnBitmask() &
722 FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
723 Object[] args = new Object[] {
724 Long.valueOf(mbThreadModelImpl.getOriginalRootMessageId())
725 };
726
727 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
728 args);
729 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
730 args);
731
732 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
733 new Object[] { Long.valueOf(mbThread.getRootMessageId()) },
734 mbThread);
735 }
736 }
737
738 return mbThread;
739 }
740
741 protected MBThread toUnwrappedModel(MBThread mbThread) {
742 if (mbThread instanceof MBThreadImpl) {
743 return mbThread;
744 }
745
746 MBThreadImpl mbThreadImpl = new MBThreadImpl();
747
748 mbThreadImpl.setNew(mbThread.isNew());
749 mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
750
751 mbThreadImpl.setThreadId(mbThread.getThreadId());
752 mbThreadImpl.setGroupId(mbThread.getGroupId());
753 mbThreadImpl.setCompanyId(mbThread.getCompanyId());
754 mbThreadImpl.setCategoryId(mbThread.getCategoryId());
755 mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
756 mbThreadImpl.setRootMessageUserId(mbThread.getRootMessageUserId());
757 mbThreadImpl.setMessageCount(mbThread.getMessageCount());
758 mbThreadImpl.setViewCount(mbThread.getViewCount());
759 mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
760 mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
761 mbThreadImpl.setPriority(mbThread.getPriority());
762 mbThreadImpl.setQuestion(mbThread.isQuestion());
763 mbThreadImpl.setStatus(mbThread.getStatus());
764 mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
765 mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
766 mbThreadImpl.setStatusDate(mbThread.getStatusDate());
767
768 return mbThreadImpl;
769 }
770
771
779 @Override
780 public MBThread findByPrimaryKey(Serializable primaryKey)
781 throws NoSuchModelException, SystemException {
782 return findByPrimaryKey(((Long)primaryKey).longValue());
783 }
784
785
793 public MBThread findByPrimaryKey(long threadId)
794 throws NoSuchThreadException, SystemException {
795 MBThread mbThread = fetchByPrimaryKey(threadId);
796
797 if (mbThread == null) {
798 if (_log.isWarnEnabled()) {
799 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
800 }
801
802 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
803 threadId);
804 }
805
806 return mbThread;
807 }
808
809
816 @Override
817 public MBThread fetchByPrimaryKey(Serializable primaryKey)
818 throws SystemException {
819 return fetchByPrimaryKey(((Long)primaryKey).longValue());
820 }
821
822
829 public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
830 MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
831 MBThreadImpl.class, threadId);
832
833 if (mbThread == _nullMBThread) {
834 return null;
835 }
836
837 if (mbThread == null) {
838 Session session = null;
839
840 boolean hasException = false;
841
842 try {
843 session = openSession();
844
845 mbThread = (MBThread)session.get(MBThreadImpl.class,
846 Long.valueOf(threadId));
847 }
848 catch (Exception e) {
849 hasException = true;
850
851 throw processException(e);
852 }
853 finally {
854 if (mbThread != null) {
855 cacheResult(mbThread);
856 }
857 else if (!hasException) {
858 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
859 MBThreadImpl.class, threadId, _nullMBThread);
860 }
861
862 closeSession(session);
863 }
864 }
865
866 return mbThread;
867 }
868
869
876 public List<MBThread> findByGroupId(long groupId) throws SystemException {
877 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
878 }
879
880
893 public List<MBThread> findByGroupId(long groupId, int start, int end)
894 throws SystemException {
895 return findByGroupId(groupId, start, end, null);
896 }
897
898
912 public List<MBThread> findByGroupId(long groupId, int start, int end,
913 OrderByComparator orderByComparator) throws SystemException {
914 FinderPath finderPath = null;
915 Object[] finderArgs = null;
916
917 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
918 (orderByComparator == null)) {
919 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
920 finderArgs = new Object[] { groupId };
921 }
922 else {
923 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
924 finderArgs = new Object[] { groupId, start, end, orderByComparator };
925 }
926
927 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
928 finderArgs, this);
929
930 if (list == null) {
931 StringBundler query = null;
932
933 if (orderByComparator != null) {
934 query = new StringBundler(3 +
935 (orderByComparator.getOrderByFields().length * 3));
936 }
937 else {
938 query = new StringBundler(3);
939 }
940
941 query.append(_SQL_SELECT_MBTHREAD_WHERE);
942
943 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
944
945 if (orderByComparator != null) {
946 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
947 orderByComparator);
948 }
949
950 else {
951 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
952 }
953
954 String sql = query.toString();
955
956 Session session = null;
957
958 try {
959 session = openSession();
960
961 Query q = session.createQuery(sql);
962
963 QueryPos qPos = QueryPos.getInstance(q);
964
965 qPos.add(groupId);
966
967 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
968 end);
969 }
970 catch (Exception e) {
971 throw processException(e);
972 }
973 finally {
974 if (list == null) {
975 FinderCacheUtil.removeResult(finderPath, finderArgs);
976 }
977 else {
978 cacheResult(list);
979
980 FinderCacheUtil.putResult(finderPath, finderArgs, list);
981 }
982
983 closeSession(session);
984 }
985 }
986
987 return list;
988 }
989
990
1003 public MBThread findByGroupId_First(long groupId,
1004 OrderByComparator orderByComparator)
1005 throws NoSuchThreadException, SystemException {
1006 List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
1007
1008 if (list.isEmpty()) {
1009 StringBundler msg = new StringBundler(4);
1010
1011 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1012
1013 msg.append("groupId=");
1014 msg.append(groupId);
1015
1016 msg.append(StringPool.CLOSE_CURLY_BRACE);
1017
1018 throw new NoSuchThreadException(msg.toString());
1019 }
1020 else {
1021 return list.get(0);
1022 }
1023 }
1024
1025
1038 public MBThread findByGroupId_Last(long groupId,
1039 OrderByComparator orderByComparator)
1040 throws NoSuchThreadException, SystemException {
1041 int count = countByGroupId(groupId);
1042
1043 List<MBThread> list = findByGroupId(groupId, count - 1, count,
1044 orderByComparator);
1045
1046 if (list.isEmpty()) {
1047 StringBundler msg = new StringBundler(4);
1048
1049 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1050
1051 msg.append("groupId=");
1052 msg.append(groupId);
1053
1054 msg.append(StringPool.CLOSE_CURLY_BRACE);
1055
1056 throw new NoSuchThreadException(msg.toString());
1057 }
1058 else {
1059 return list.get(0);
1060 }
1061 }
1062
1063
1077 public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
1078 OrderByComparator orderByComparator)
1079 throws NoSuchThreadException, SystemException {
1080 MBThread mbThread = findByPrimaryKey(threadId);
1081
1082 Session session = null;
1083
1084 try {
1085 session = openSession();
1086
1087 MBThread[] array = new MBThreadImpl[3];
1088
1089 array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1090 orderByComparator, true);
1091
1092 array[1] = mbThread;
1093
1094 array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1095 orderByComparator, false);
1096
1097 return array;
1098 }
1099 catch (Exception e) {
1100 throw processException(e);
1101 }
1102 finally {
1103 closeSession(session);
1104 }
1105 }
1106
1107 protected MBThread getByGroupId_PrevAndNext(Session session,
1108 MBThread mbThread, long groupId, OrderByComparator orderByComparator,
1109 boolean previous) {
1110 StringBundler query = null;
1111
1112 if (orderByComparator != null) {
1113 query = new StringBundler(6 +
1114 (orderByComparator.getOrderByFields().length * 6));
1115 }
1116 else {
1117 query = new StringBundler(3);
1118 }
1119
1120 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1121
1122 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1123
1124 if (orderByComparator != null) {
1125 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1126
1127 if (orderByConditionFields.length > 0) {
1128 query.append(WHERE_AND);
1129 }
1130
1131 for (int i = 0; i < orderByConditionFields.length; i++) {
1132 query.append(_ORDER_BY_ENTITY_ALIAS);
1133 query.append(orderByConditionFields[i]);
1134
1135 if ((i + 1) < orderByConditionFields.length) {
1136 if (orderByComparator.isAscending() ^ previous) {
1137 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1138 }
1139 else {
1140 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1141 }
1142 }
1143 else {
1144 if (orderByComparator.isAscending() ^ previous) {
1145 query.append(WHERE_GREATER_THAN);
1146 }
1147 else {
1148 query.append(WHERE_LESSER_THAN);
1149 }
1150 }
1151 }
1152
1153 query.append(ORDER_BY_CLAUSE);
1154
1155 String[] orderByFields = orderByComparator.getOrderByFields();
1156
1157 for (int i = 0; i < orderByFields.length; i++) {
1158 query.append(_ORDER_BY_ENTITY_ALIAS);
1159 query.append(orderByFields[i]);
1160
1161 if ((i + 1) < orderByFields.length) {
1162 if (orderByComparator.isAscending() ^ previous) {
1163 query.append(ORDER_BY_ASC_HAS_NEXT);
1164 }
1165 else {
1166 query.append(ORDER_BY_DESC_HAS_NEXT);
1167 }
1168 }
1169 else {
1170 if (orderByComparator.isAscending() ^ previous) {
1171 query.append(ORDER_BY_ASC);
1172 }
1173 else {
1174 query.append(ORDER_BY_DESC);
1175 }
1176 }
1177 }
1178 }
1179
1180 else {
1181 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1182 }
1183
1184 String sql = query.toString();
1185
1186 Query q = session.createQuery(sql);
1187
1188 q.setFirstResult(0);
1189 q.setMaxResults(2);
1190
1191 QueryPos qPos = QueryPos.getInstance(q);
1192
1193 qPos.add(groupId);
1194
1195 if (orderByComparator != null) {
1196 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1197
1198 for (Object value : values) {
1199 qPos.add(value);
1200 }
1201 }
1202
1203 List<MBThread> list = q.list();
1204
1205 if (list.size() == 2) {
1206 return list.get(1);
1207 }
1208 else {
1209 return null;
1210 }
1211 }
1212
1213
1220 public List<MBThread> filterFindByGroupId(long groupId)
1221 throws SystemException {
1222 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1223 QueryUtil.ALL_POS, null);
1224 }
1225
1226
1239 public List<MBThread> filterFindByGroupId(long groupId, int start, int end)
1240 throws SystemException {
1241 return filterFindByGroupId(groupId, start, end, null);
1242 }
1243
1244
1258 public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
1259 OrderByComparator orderByComparator) throws SystemException {
1260 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1261 return findByGroupId(groupId, start, end, orderByComparator);
1262 }
1263
1264 StringBundler query = null;
1265
1266 if (orderByComparator != null) {
1267 query = new StringBundler(3 +
1268 (orderByComparator.getOrderByFields().length * 3));
1269 }
1270 else {
1271 query = new StringBundler(3);
1272 }
1273
1274 if (getDB().isSupportsInlineDistinct()) {
1275 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1276 }
1277 else {
1278 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1279 }
1280
1281 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1282
1283 if (!getDB().isSupportsInlineDistinct()) {
1284 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1285 }
1286
1287 if (orderByComparator != null) {
1288 if (getDB().isSupportsInlineDistinct()) {
1289 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1290 orderByComparator);
1291 }
1292 else {
1293 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1294 orderByComparator);
1295 }
1296 }
1297
1298 else {
1299 if (getDB().isSupportsInlineDistinct()) {
1300 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1301 }
1302 else {
1303 query.append(MBThreadModelImpl.ORDER_BY_SQL);
1304 }
1305 }
1306
1307 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1308 MBThread.class.getName(),
1309 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1310
1311 Session session = null;
1312
1313 try {
1314 session = openSession();
1315
1316 SQLQuery q = session.createSQLQuery(sql);
1317
1318 if (getDB().isSupportsInlineDistinct()) {
1319 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1320 }
1321 else {
1322 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1323 }
1324
1325 QueryPos qPos = QueryPos.getInstance(q);
1326
1327 qPos.add(groupId);
1328
1329 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
1330 }
1331 catch (Exception e) {
1332 throw processException(e);
1333 }
1334 finally {
1335 closeSession(session);
1336 }
1337 }
1338
1339
1349 public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
1350 long groupId, OrderByComparator orderByComparator)
1351 throws NoSuchThreadException, SystemException {
1352 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1353 return findByGroupId_PrevAndNext(threadId, groupId,
1354 orderByComparator);
1355 }
1356
1357 MBThread mbThread = findByPrimaryKey(threadId);
1358
1359 Session session = null;
1360
1361 try {
1362 session = openSession();
1363
1364 MBThread[] array = new MBThreadImpl[3];
1365
1366 array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
1367 groupId, orderByComparator, true);
1368
1369 array[1] = mbThread;
1370
1371 array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
1372 groupId, orderByComparator, false);
1373
1374 return array;
1375 }
1376 catch (Exception e) {
1377 throw processException(e);
1378 }
1379 finally {
1380 closeSession(session);
1381 }
1382 }
1383
1384 protected MBThread filterGetByGroupId_PrevAndNext(Session session,
1385 MBThread mbThread, long groupId, OrderByComparator orderByComparator,
1386 boolean previous) {
1387 StringBundler query = null;
1388
1389 if (orderByComparator != null) {
1390 query = new StringBundler(6 +
1391 (orderByComparator.getOrderByFields().length * 6));
1392 }
1393 else {
1394 query = new StringBundler(3);
1395 }
1396
1397 if (getDB().isSupportsInlineDistinct()) {
1398 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1399 }
1400 else {
1401 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1402 }
1403
1404 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1405
1406 if (!getDB().isSupportsInlineDistinct()) {
1407 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1408 }
1409
1410 if (orderByComparator != null) {
1411 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1412
1413 if (orderByConditionFields.length > 0) {
1414 query.append(WHERE_AND);
1415 }
1416
1417 for (int i = 0; i < orderByConditionFields.length; i++) {
1418 if (getDB().isSupportsInlineDistinct()) {
1419 query.append(_ORDER_BY_ENTITY_ALIAS);
1420 }
1421 else {
1422 query.append(_ORDER_BY_ENTITY_TABLE);
1423 }
1424
1425 query.append(orderByConditionFields[i]);
1426
1427 if ((i + 1) < orderByConditionFields.length) {
1428 if (orderByComparator.isAscending() ^ previous) {
1429 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1430 }
1431 else {
1432 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1433 }
1434 }
1435 else {
1436 if (orderByComparator.isAscending() ^ previous) {
1437 query.append(WHERE_GREATER_THAN);
1438 }
1439 else {
1440 query.append(WHERE_LESSER_THAN);
1441 }
1442 }
1443 }
1444
1445 query.append(ORDER_BY_CLAUSE);
1446
1447 String[] orderByFields = orderByComparator.getOrderByFields();
1448
1449 for (int i = 0; i < orderByFields.length; i++) {
1450 if (getDB().isSupportsInlineDistinct()) {
1451 query.append(_ORDER_BY_ENTITY_ALIAS);
1452 }
1453 else {
1454 query.append(_ORDER_BY_ENTITY_TABLE);
1455 }
1456
1457 query.append(orderByFields[i]);
1458
1459 if ((i + 1) < orderByFields.length) {
1460 if (orderByComparator.isAscending() ^ previous) {
1461 query.append(ORDER_BY_ASC_HAS_NEXT);
1462 }
1463 else {
1464 query.append(ORDER_BY_DESC_HAS_NEXT);
1465 }
1466 }
1467 else {
1468 if (orderByComparator.isAscending() ^ previous) {
1469 query.append(ORDER_BY_ASC);
1470 }
1471 else {
1472 query.append(ORDER_BY_DESC);
1473 }
1474 }
1475 }
1476 }
1477
1478 else {
1479 if (getDB().isSupportsInlineDistinct()) {
1480 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1481 }
1482 else {
1483 query.append(MBThreadModelImpl.ORDER_BY_SQL);
1484 }
1485 }
1486
1487 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1488 MBThread.class.getName(),
1489 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1490
1491 SQLQuery q = session.createSQLQuery(sql);
1492
1493 q.setFirstResult(0);
1494 q.setMaxResults(2);
1495
1496 if (getDB().isSupportsInlineDistinct()) {
1497 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1498 }
1499 else {
1500 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1501 }
1502
1503 QueryPos qPos = QueryPos.getInstance(q);
1504
1505 qPos.add(groupId);
1506
1507 if (orderByComparator != null) {
1508 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1509
1510 for (Object value : values) {
1511 qPos.add(value);
1512 }
1513 }
1514
1515 List<MBThread> list = q.list();
1516
1517 if (list.size() == 2) {
1518 return list.get(1);
1519 }
1520 else {
1521 return null;
1522 }
1523 }
1524
1525
1533 public MBThread findByRootMessageId(long rootMessageId)
1534 throws NoSuchThreadException, SystemException {
1535 MBThread mbThread = fetchByRootMessageId(rootMessageId);
1536
1537 if (mbThread == null) {
1538 StringBundler msg = new StringBundler(4);
1539
1540 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1541
1542 msg.append("rootMessageId=");
1543 msg.append(rootMessageId);
1544
1545 msg.append(StringPool.CLOSE_CURLY_BRACE);
1546
1547 if (_log.isWarnEnabled()) {
1548 _log.warn(msg.toString());
1549 }
1550
1551 throw new NoSuchThreadException(msg.toString());
1552 }
1553
1554 return mbThread;
1555 }
1556
1557
1564 public MBThread fetchByRootMessageId(long rootMessageId)
1565 throws SystemException {
1566 return fetchByRootMessageId(rootMessageId, true);
1567 }
1568
1569
1577 public MBThread fetchByRootMessageId(long rootMessageId,
1578 boolean retrieveFromCache) throws SystemException {
1579 Object[] finderArgs = new Object[] { rootMessageId };
1580
1581 Object result = null;
1582
1583 if (retrieveFromCache) {
1584 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1585 finderArgs, this);
1586 }
1587
1588 if (result == null) {
1589 StringBundler query = new StringBundler(3);
1590
1591 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1592
1593 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
1594
1595 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1596
1597 String sql = query.toString();
1598
1599 Session session = null;
1600
1601 try {
1602 session = openSession();
1603
1604 Query q = session.createQuery(sql);
1605
1606 QueryPos qPos = QueryPos.getInstance(q);
1607
1608 qPos.add(rootMessageId);
1609
1610 List<MBThread> list = q.list();
1611
1612 result = list;
1613
1614 MBThread mbThread = null;
1615
1616 if (list.isEmpty()) {
1617 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1618 finderArgs, list);
1619 }
1620 else {
1621 mbThread = list.get(0);
1622
1623 cacheResult(mbThread);
1624
1625 if ((mbThread.getRootMessageId() != rootMessageId)) {
1626 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1627 finderArgs, mbThread);
1628 }
1629 }
1630
1631 return mbThread;
1632 }
1633 catch (Exception e) {
1634 throw processException(e);
1635 }
1636 finally {
1637 if (result == null) {
1638 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1639 finderArgs);
1640 }
1641
1642 closeSession(session);
1643 }
1644 }
1645 else {
1646 if (result instanceof List<?>) {
1647 return null;
1648 }
1649 else {
1650 return (MBThread)result;
1651 }
1652 }
1653 }
1654
1655
1663 public List<MBThread> findByG_C(long groupId, long categoryId)
1664 throws SystemException {
1665 return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
1666 QueryUtil.ALL_POS, null);
1667 }
1668
1669
1683 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
1684 int end) throws SystemException {
1685 return findByG_C(groupId, categoryId, start, end, null);
1686 }
1687
1688
1703 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
1704 int end, OrderByComparator orderByComparator) throws SystemException {
1705 FinderPath finderPath = null;
1706 Object[] finderArgs = null;
1707
1708 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1709 (orderByComparator == null)) {
1710 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
1711 finderArgs = new Object[] { groupId, categoryId };
1712 }
1713 else {
1714 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
1715 finderArgs = new Object[] {
1716 groupId, categoryId,
1717
1718 start, end, orderByComparator
1719 };
1720 }
1721
1722 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
1723 finderArgs, this);
1724
1725 if (list == null) {
1726 StringBundler query = null;
1727
1728 if (orderByComparator != null) {
1729 query = new StringBundler(4 +
1730 (orderByComparator.getOrderByFields().length * 3));
1731 }
1732 else {
1733 query = new StringBundler(4);
1734 }
1735
1736 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1737
1738 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1739
1740 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1741
1742 if (orderByComparator != null) {
1743 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1744 orderByComparator);
1745 }
1746
1747 else {
1748 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1749 }
1750
1751 String sql = query.toString();
1752
1753 Session session = null;
1754
1755 try {
1756 session = openSession();
1757
1758 Query q = session.createQuery(sql);
1759
1760 QueryPos qPos = QueryPos.getInstance(q);
1761
1762 qPos.add(groupId);
1763
1764 qPos.add(categoryId);
1765
1766 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1767 end);
1768 }
1769 catch (Exception e) {
1770 throw processException(e);
1771 }
1772 finally {
1773 if (list == null) {
1774 FinderCacheUtil.removeResult(finderPath, finderArgs);
1775 }
1776 else {
1777 cacheResult(list);
1778
1779 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1780 }
1781
1782 closeSession(session);
1783 }
1784 }
1785
1786 return list;
1787 }
1788
1789
1803 public MBThread findByG_C_First(long groupId, long categoryId,
1804 OrderByComparator orderByComparator)
1805 throws NoSuchThreadException, SystemException {
1806 List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
1807 orderByComparator);
1808
1809 if (list.isEmpty()) {
1810 StringBundler msg = new StringBundler(6);
1811
1812 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1813
1814 msg.append("groupId=");
1815 msg.append(groupId);
1816
1817 msg.append(", categoryId=");
1818 msg.append(categoryId);
1819
1820 msg.append(StringPool.CLOSE_CURLY_BRACE);
1821
1822 throw new NoSuchThreadException(msg.toString());
1823 }
1824 else {
1825 return list.get(0);
1826 }
1827 }
1828
1829
1843 public MBThread findByG_C_Last(long groupId, long categoryId,
1844 OrderByComparator orderByComparator)
1845 throws NoSuchThreadException, SystemException {
1846 int count = countByG_C(groupId, categoryId);
1847
1848 List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
1849 orderByComparator);
1850
1851 if (list.isEmpty()) {
1852 StringBundler msg = new StringBundler(6);
1853
1854 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1855
1856 msg.append("groupId=");
1857 msg.append(groupId);
1858
1859 msg.append(", categoryId=");
1860 msg.append(categoryId);
1861
1862 msg.append(StringPool.CLOSE_CURLY_BRACE);
1863
1864 throw new NoSuchThreadException(msg.toString());
1865 }
1866 else {
1867 return list.get(0);
1868 }
1869 }
1870
1871
1886 public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
1887 long categoryId, OrderByComparator orderByComparator)
1888 throws NoSuchThreadException, SystemException {
1889 MBThread mbThread = findByPrimaryKey(threadId);
1890
1891 Session session = null;
1892
1893 try {
1894 session = openSession();
1895
1896 MBThread[] array = new MBThreadImpl[3];
1897
1898 array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
1899 categoryId, orderByComparator, true);
1900
1901 array[1] = mbThread;
1902
1903 array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
1904 categoryId, orderByComparator, false);
1905
1906 return array;
1907 }
1908 catch (Exception e) {
1909 throw processException(e);
1910 }
1911 finally {
1912 closeSession(session);
1913 }
1914 }
1915
1916 protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
1917 long groupId, long categoryId, OrderByComparator orderByComparator,
1918 boolean previous) {
1919 StringBundler query = null;
1920
1921 if (orderByComparator != null) {
1922 query = new StringBundler(6 +
1923 (orderByComparator.getOrderByFields().length * 6));
1924 }
1925 else {
1926 query = new StringBundler(3);
1927 }
1928
1929 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1930
1931 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1932
1933 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1934
1935 if (orderByComparator != null) {
1936 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1937
1938 if (orderByConditionFields.length > 0) {
1939 query.append(WHERE_AND);
1940 }
1941
1942 for (int i = 0; i < orderByConditionFields.length; i++) {
1943 query.append(_ORDER_BY_ENTITY_ALIAS);
1944 query.append(orderByConditionFields[i]);
1945
1946 if ((i + 1) < orderByConditionFields.length) {
1947 if (orderByComparator.isAscending() ^ previous) {
1948 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1949 }
1950 else {
1951 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1952 }
1953 }
1954 else {
1955 if (orderByComparator.isAscending() ^ previous) {
1956 query.append(WHERE_GREATER_THAN);
1957 }
1958 else {
1959 query.append(WHERE_LESSER_THAN);
1960 }
1961 }
1962 }
1963
1964 query.append(ORDER_BY_CLAUSE);
1965
1966 String[] orderByFields = orderByComparator.getOrderByFields();
1967
1968 for (int i = 0; i < orderByFields.length; i++) {
1969 query.append(_ORDER_BY_ENTITY_ALIAS);
1970 query.append(orderByFields[i]);
1971
1972 if ((i + 1) < orderByFields.length) {
1973 if (orderByComparator.isAscending() ^ previous) {
1974 query.append(ORDER_BY_ASC_HAS_NEXT);
1975 }
1976 else {
1977 query.append(ORDER_BY_DESC_HAS_NEXT);
1978 }
1979 }
1980 else {
1981 if (orderByComparator.isAscending() ^ previous) {
1982 query.append(ORDER_BY_ASC);
1983 }
1984 else {
1985 query.append(ORDER_BY_DESC);
1986 }
1987 }
1988 }
1989 }
1990
1991 else {
1992 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1993 }
1994
1995 String sql = query.toString();
1996
1997 Query q = session.createQuery(sql);
1998
1999 q.setFirstResult(0);
2000 q.setMaxResults(2);
2001
2002 QueryPos qPos = QueryPos.getInstance(q);
2003
2004 qPos.add(groupId);
2005
2006 qPos.add(categoryId);
2007
2008 if (orderByComparator != null) {
2009 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2010
2011 for (Object value : values) {
2012 qPos.add(value);
2013 }
2014 }
2015
2016 List<MBThread> list = q.list();
2017
2018 if (list.size() == 2) {
2019 return list.get(1);
2020 }
2021 else {
2022 return null;
2023 }
2024 }
2025
2026
2038 public List<MBThread> findByG_C(long groupId, long[] categoryIds)
2039 throws SystemException {
2040 return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
2041 QueryUtil.ALL_POS, null);
2042 }
2043
2044
2058 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
2059 int start, int end) throws SystemException {
2060 return findByG_C(groupId, categoryIds, start, end, null);
2061 }
2062
2063
2078 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
2079 int start, int end, OrderByComparator orderByComparator)
2080 throws SystemException {
2081 FinderPath finderPath = null;
2082 Object[] finderArgs = null;
2083
2084 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2085 (orderByComparator == null)) {
2086 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
2087 finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
2088 }
2089 else {
2090 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
2091 finderArgs = new Object[] {
2092 groupId, StringUtil.merge(categoryIds),
2093
2094 start, end, orderByComparator
2095 };
2096 }
2097
2098 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2099 finderArgs, this);
2100
2101 if (list == null) {
2102 StringBundler query = new StringBundler();
2103
2104 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2105
2106 boolean conjunctionable = false;
2107
2108 if (conjunctionable) {
2109 query.append(WHERE_AND);
2110 }
2111
2112 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2113
2114 conjunctionable = true;
2115
2116 if ((categoryIds == null) || (categoryIds.length > 0)) {
2117 if (conjunctionable) {
2118 query.append(WHERE_AND);
2119 }
2120
2121 query.append(StringPool.OPEN_PARENTHESIS);
2122
2123 for (int i = 0; i < categoryIds.length; i++) {
2124 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2125
2126 if ((i + 1) < categoryIds.length) {
2127 query.append(WHERE_OR);
2128 }
2129 }
2130
2131 query.append(StringPool.CLOSE_PARENTHESIS);
2132
2133 conjunctionable = true;
2134 }
2135
2136 if (orderByComparator != null) {
2137 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2138 orderByComparator);
2139 }
2140
2141 else {
2142 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2143 }
2144
2145 String sql = query.toString();
2146
2147 Session session = null;
2148
2149 try {
2150 session = openSession();
2151
2152 Query q = session.createQuery(sql);
2153
2154 QueryPos qPos = QueryPos.getInstance(q);
2155
2156 qPos.add(groupId);
2157
2158 if (categoryIds != null) {
2159 qPos.add(categoryIds);
2160 }
2161
2162 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2163 end);
2164 }
2165 catch (Exception e) {
2166 throw processException(e);
2167 }
2168 finally {
2169 if (list == null) {
2170 FinderCacheUtil.removeResult(finderPath, finderArgs);
2171 }
2172 else {
2173 cacheResult(list);
2174
2175 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2176 }
2177
2178 closeSession(session);
2179 }
2180 }
2181
2182 return list;
2183 }
2184
2185
2193 public List<MBThread> filterFindByG_C(long groupId, long categoryId)
2194 throws SystemException {
2195 return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2196 QueryUtil.ALL_POS, null);
2197 }
2198
2199
2213 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2214 int start, int end) throws SystemException {
2215 return filterFindByG_C(groupId, categoryId, start, end, null);
2216 }
2217
2218
2233 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2234 int start, int end, OrderByComparator orderByComparator)
2235 throws SystemException {
2236 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2237 return findByG_C(groupId, categoryId, start, end, orderByComparator);
2238 }
2239
2240 StringBundler query = null;
2241
2242 if (orderByComparator != null) {
2243 query = new StringBundler(4 +
2244 (orderByComparator.getOrderByFields().length * 3));
2245 }
2246 else {
2247 query = new StringBundler(4);
2248 }
2249
2250 if (getDB().isSupportsInlineDistinct()) {
2251 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2252 }
2253 else {
2254 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2255 }
2256
2257 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2258
2259 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2260
2261 if (!getDB().isSupportsInlineDistinct()) {
2262 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2263 }
2264
2265 if (orderByComparator != null) {
2266 if (getDB().isSupportsInlineDistinct()) {
2267 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2268 orderByComparator);
2269 }
2270 else {
2271 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2272 orderByComparator);
2273 }
2274 }
2275
2276 else {
2277 if (getDB().isSupportsInlineDistinct()) {
2278 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2279 }
2280 else {
2281 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2282 }
2283 }
2284
2285 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2286 MBThread.class.getName(),
2287 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2288
2289 Session session = null;
2290
2291 try {
2292 session = openSession();
2293
2294 SQLQuery q = session.createSQLQuery(sql);
2295
2296 if (getDB().isSupportsInlineDistinct()) {
2297 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2298 }
2299 else {
2300 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2301 }
2302
2303 QueryPos qPos = QueryPos.getInstance(q);
2304
2305 qPos.add(groupId);
2306
2307 qPos.add(categoryId);
2308
2309 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
2310 }
2311 catch (Exception e) {
2312 throw processException(e);
2313 }
2314 finally {
2315 closeSession(session);
2316 }
2317 }
2318
2319
2330 public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
2331 long categoryId, OrderByComparator orderByComparator)
2332 throws NoSuchThreadException, SystemException {
2333 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2334 return findByG_C_PrevAndNext(threadId, groupId, categoryId,
2335 orderByComparator);
2336 }
2337
2338 MBThread mbThread = findByPrimaryKey(threadId);
2339
2340 Session session = null;
2341
2342 try {
2343 session = openSession();
2344
2345 MBThread[] array = new MBThreadImpl[3];
2346
2347 array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
2348 categoryId, orderByComparator, true);
2349
2350 array[1] = mbThread;
2351
2352 array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
2353 categoryId, orderByComparator, false);
2354
2355 return array;
2356 }
2357 catch (Exception e) {
2358 throw processException(e);
2359 }
2360 finally {
2361 closeSession(session);
2362 }
2363 }
2364
2365 protected MBThread filterGetByG_C_PrevAndNext(Session session,
2366 MBThread mbThread, long groupId, long categoryId,
2367 OrderByComparator orderByComparator, boolean previous) {
2368 StringBundler query = null;
2369
2370 if (orderByComparator != null) {
2371 query = new StringBundler(6 +
2372 (orderByComparator.getOrderByFields().length * 6));
2373 }
2374 else {
2375 query = new StringBundler(3);
2376 }
2377
2378 if (getDB().isSupportsInlineDistinct()) {
2379 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2380 }
2381 else {
2382 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2383 }
2384
2385 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2386
2387 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2388
2389 if (!getDB().isSupportsInlineDistinct()) {
2390 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2391 }
2392
2393 if (orderByComparator != null) {
2394 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2395
2396 if (orderByConditionFields.length > 0) {
2397 query.append(WHERE_AND);
2398 }
2399
2400 for (int i = 0; i < orderByConditionFields.length; i++) {
2401 if (getDB().isSupportsInlineDistinct()) {
2402 query.append(_ORDER_BY_ENTITY_ALIAS);
2403 }
2404 else {
2405 query.append(_ORDER_BY_ENTITY_TABLE);
2406 }
2407
2408 query.append(orderByConditionFields[i]);
2409
2410 if ((i + 1) < orderByConditionFields.length) {
2411 if (orderByComparator.isAscending() ^ previous) {
2412 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2413 }
2414 else {
2415 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2416 }
2417 }
2418 else {
2419 if (orderByComparator.isAscending() ^ previous) {
2420 query.append(WHERE_GREATER_THAN);
2421 }
2422 else {
2423 query.append(WHERE_LESSER_THAN);
2424 }
2425 }
2426 }
2427
2428 query.append(ORDER_BY_CLAUSE);
2429
2430 String[] orderByFields = orderByComparator.getOrderByFields();
2431
2432 for (int i = 0; i < orderByFields.length; i++) {
2433 if (getDB().isSupportsInlineDistinct()) {
2434 query.append(_ORDER_BY_ENTITY_ALIAS);
2435 }
2436 else {
2437 query.append(_ORDER_BY_ENTITY_TABLE);
2438 }
2439
2440 query.append(orderByFields[i]);
2441
2442 if ((i + 1) < orderByFields.length) {
2443 if (orderByComparator.isAscending() ^ previous) {
2444 query.append(ORDER_BY_ASC_HAS_NEXT);
2445 }
2446 else {
2447 query.append(ORDER_BY_DESC_HAS_NEXT);
2448 }
2449 }
2450 else {
2451 if (orderByComparator.isAscending() ^ previous) {
2452 query.append(ORDER_BY_ASC);
2453 }
2454 else {
2455 query.append(ORDER_BY_DESC);
2456 }
2457 }
2458 }
2459 }
2460
2461 else {
2462 if (getDB().isSupportsInlineDistinct()) {
2463 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2464 }
2465 else {
2466 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2467 }
2468 }
2469
2470 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2471 MBThread.class.getName(),
2472 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2473
2474 SQLQuery q = session.createSQLQuery(sql);
2475
2476 q.setFirstResult(0);
2477 q.setMaxResults(2);
2478
2479 if (getDB().isSupportsInlineDistinct()) {
2480 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2481 }
2482 else {
2483 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2484 }
2485
2486 QueryPos qPos = QueryPos.getInstance(q);
2487
2488 qPos.add(groupId);
2489
2490 qPos.add(categoryId);
2491
2492 if (orderByComparator != null) {
2493 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2494
2495 for (Object value : values) {
2496 qPos.add(value);
2497 }
2498 }
2499
2500 List<MBThread> list = q.list();
2501
2502 if (list.size() == 2) {
2503 return list.get(1);
2504 }
2505 else {
2506 return null;
2507 }
2508 }
2509
2510
2518 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds)
2519 throws SystemException {
2520 return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
2521 QueryUtil.ALL_POS, null);
2522 }
2523
2524
2538 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
2539 int start, int end) throws SystemException {
2540 return filterFindByG_C(groupId, categoryIds, start, end, null);
2541 }
2542
2543
2558 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
2559 int start, int end, OrderByComparator orderByComparator)
2560 throws SystemException {
2561 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2562 return findByG_C(groupId, categoryIds, start, end, orderByComparator);
2563 }
2564
2565 StringBundler query = new StringBundler();
2566
2567 if (getDB().isSupportsInlineDistinct()) {
2568 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2569 }
2570 else {
2571 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2572 }
2573
2574 boolean conjunctionable = false;
2575
2576 if (conjunctionable) {
2577 query.append(WHERE_AND);
2578 }
2579
2580 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2581
2582 conjunctionable = true;
2583
2584 if ((categoryIds == null) || (categoryIds.length > 0)) {
2585 if (conjunctionable) {
2586 query.append(WHERE_AND);
2587 }
2588
2589 query.append(StringPool.OPEN_PARENTHESIS);
2590
2591 for (int i = 0; i < categoryIds.length; i++) {
2592 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2593
2594 if ((i + 1) < categoryIds.length) {
2595 query.append(WHERE_OR);
2596 }
2597 }
2598
2599 query.append(StringPool.CLOSE_PARENTHESIS);
2600
2601 conjunctionable = true;
2602 }
2603
2604 if (!getDB().isSupportsInlineDistinct()) {
2605 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2606 }
2607
2608 if (orderByComparator != null) {
2609 if (getDB().isSupportsInlineDistinct()) {
2610 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2611 orderByComparator);
2612 }
2613 else {
2614 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2615 orderByComparator);
2616 }
2617 }
2618
2619 else {
2620 if (getDB().isSupportsInlineDistinct()) {
2621 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2622 }
2623 else {
2624 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2625 }
2626 }
2627
2628 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2629 MBThread.class.getName(),
2630 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2631
2632 Session session = null;
2633
2634 try {
2635 session = openSession();
2636
2637 SQLQuery q = session.createSQLQuery(sql);
2638
2639 if (getDB().isSupportsInlineDistinct()) {
2640 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2641 }
2642 else {
2643 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2644 }
2645
2646 QueryPos qPos = QueryPos.getInstance(q);
2647
2648 qPos.add(groupId);
2649
2650 if (categoryIds != null) {
2651 qPos.add(categoryIds);
2652 }
2653
2654 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
2655 }
2656 catch (Exception e) {
2657 throw processException(e);
2658 }
2659 finally {
2660 closeSession(session);
2661 }
2662 }
2663
2664
2672 public List<MBThread> findByG_NotC(long groupId, long categoryId)
2673 throws SystemException {
2674 return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
2675 QueryUtil.ALL_POS, null);
2676 }
2677
2678
2692 public List<MBThread> findByG_NotC(long groupId, long categoryId,
2693 int start, int end) throws SystemException {
2694 return findByG_NotC(groupId, categoryId, start, end, null);
2695 }
2696
2697
2712 public List<MBThread> findByG_NotC(long groupId, long categoryId,
2713 int start, int end, OrderByComparator orderByComparator)
2714 throws SystemException {
2715 FinderPath finderPath = null;
2716 Object[] finderArgs = null;
2717
2718 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2719 (orderByComparator == null)) {
2720 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC;
2721 finderArgs = new Object[] { groupId, categoryId };
2722 }
2723 else {
2724 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
2725 finderArgs = new Object[] {
2726 groupId, categoryId,
2727
2728 start, end, orderByComparator
2729 };
2730 }
2731
2732 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2733 finderArgs, this);
2734
2735 if (list == null) {
2736 StringBundler query = null;
2737
2738 if (orderByComparator != null) {
2739 query = new StringBundler(4 +
2740 (orderByComparator.getOrderByFields().length * 3));
2741 }
2742 else {
2743 query = new StringBundler(4);
2744 }
2745
2746 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2747
2748 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
2749
2750 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
2751
2752 if (orderByComparator != null) {
2753 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2754 orderByComparator);
2755 }
2756
2757 else {
2758 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2759 }
2760
2761 String sql = query.toString();
2762
2763 Session session = null;
2764
2765 try {
2766 session = openSession();
2767
2768 Query q = session.createQuery(sql);
2769
2770 QueryPos qPos = QueryPos.getInstance(q);
2771
2772 qPos.add(groupId);
2773
2774 qPos.add(categoryId);
2775
2776 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2777 end);
2778 }
2779 catch (Exception e) {
2780 throw processException(e);
2781 }
2782 finally {
2783 if (list == null) {
2784 FinderCacheUtil.removeResult(finderPath, finderArgs);
2785 }
2786 else {
2787 cacheResult(list);
2788
2789 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2790 }
2791
2792 closeSession(session);
2793 }
2794 }
2795
2796 return list;
2797 }
2798
2799
2813 public MBThread findByG_NotC_First(long groupId, long categoryId,
2814 OrderByComparator orderByComparator)
2815 throws NoSuchThreadException, SystemException {
2816 List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
2817 orderByComparator);
2818
2819 if (list.isEmpty()) {
2820 StringBundler msg = new StringBundler(6);
2821
2822 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2823
2824 msg.append("groupId=");
2825 msg.append(groupId);
2826
2827 msg.append(", categoryId=");
2828 msg.append(categoryId);
2829
2830 msg.append(StringPool.CLOSE_CURLY_BRACE);
2831
2832 throw new NoSuchThreadException(msg.toString());
2833 }
2834 else {
2835 return list.get(0);
2836 }
2837 }
2838
2839
2853 public MBThread findByG_NotC_Last(long groupId, long categoryId,
2854 OrderByComparator orderByComparator)
2855 throws NoSuchThreadException, SystemException {
2856 int count = countByG_NotC(groupId, categoryId);
2857
2858 List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
2859 count, orderByComparator);
2860
2861 if (list.isEmpty()) {
2862 StringBundler msg = new StringBundler(6);
2863
2864 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2865
2866 msg.append("groupId=");
2867 msg.append(groupId);
2868
2869 msg.append(", categoryId=");
2870 msg.append(categoryId);
2871
2872 msg.append(StringPool.CLOSE_CURLY_BRACE);
2873
2874 throw new NoSuchThreadException(msg.toString());
2875 }
2876 else {
2877 return list.get(0);
2878 }
2879 }
2880
2881
2896 public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
2897 long categoryId, OrderByComparator orderByComparator)
2898 throws NoSuchThreadException, SystemException {
2899 MBThread mbThread = findByPrimaryKey(threadId);
2900
2901 Session session = null;
2902
2903 try {
2904 session = openSession();
2905
2906 MBThread[] array = new MBThreadImpl[3];
2907
2908 array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
2909 categoryId, orderByComparator, true);
2910
2911 array[1] = mbThread;
2912
2913 array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
2914 categoryId, orderByComparator, false);
2915
2916 return array;
2917 }
2918 catch (Exception e) {
2919 throw processException(e);
2920 }
2921 finally {
2922 closeSession(session);
2923 }
2924 }
2925
2926 protected MBThread getByG_NotC_PrevAndNext(Session session,
2927 MBThread mbThread, long groupId, long categoryId,
2928 OrderByComparator orderByComparator, boolean previous) {
2929 StringBundler query = null;
2930
2931 if (orderByComparator != null) {
2932 query = new StringBundler(6 +
2933 (orderByComparator.getOrderByFields().length * 6));
2934 }
2935 else {
2936 query = new StringBundler(3);
2937 }
2938
2939 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2940
2941 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
2942
2943 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
2944
2945 if (orderByComparator != null) {
2946 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2947
2948 if (orderByConditionFields.length > 0) {
2949 query.append(WHERE_AND);
2950 }
2951
2952 for (int i = 0; i < orderByConditionFields.length; i++) {
2953 query.append(_ORDER_BY_ENTITY_ALIAS);
2954 query.append(orderByConditionFields[i]);
2955
2956 if ((i + 1) < orderByConditionFields.length) {
2957 if (orderByComparator.isAscending() ^ previous) {
2958 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2959 }
2960 else {
2961 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2962 }
2963 }
2964 else {
2965 if (orderByComparator.isAscending() ^ previous) {
2966 query.append(WHERE_GREATER_THAN);
2967 }
2968 else {
2969 query.append(WHERE_LESSER_THAN);
2970 }
2971 }
2972 }
2973
2974 query.append(ORDER_BY_CLAUSE);
2975
2976 String[] orderByFields = orderByComparator.getOrderByFields();
2977
2978 for (int i = 0; i < orderByFields.length; i++) {
2979 query.append(_ORDER_BY_ENTITY_ALIAS);
2980 query.append(orderByFields[i]);
2981
2982 if ((i + 1) < orderByFields.length) {
2983 if (orderByComparator.isAscending() ^ previous) {
2984 query.append(ORDER_BY_ASC_HAS_NEXT);
2985 }
2986 else {
2987 query.append(ORDER_BY_DESC_HAS_NEXT);
2988 }
2989 }
2990 else {
2991 if (orderByComparator.isAscending() ^ previous) {
2992 query.append(ORDER_BY_ASC);
2993 }
2994 else {
2995 query.append(ORDER_BY_DESC);
2996 }
2997 }
2998 }
2999 }
3000
3001 else {
3002 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3003 }
3004
3005 String sql = query.toString();
3006
3007 Query q = session.createQuery(sql);
3008
3009 q.setFirstResult(0);
3010 q.setMaxResults(2);
3011
3012 QueryPos qPos = QueryPos.getInstance(q);
3013
3014 qPos.add(groupId);
3015
3016 qPos.add(categoryId);
3017
3018 if (orderByComparator != null) {
3019 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3020
3021 for (Object value : values) {
3022 qPos.add(value);
3023 }
3024 }
3025
3026 List<MBThread> list = q.list();
3027
3028 if (list.size() == 2) {
3029 return list.get(1);
3030 }
3031 else {
3032 return null;
3033 }
3034 }
3035
3036
3044 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId)
3045 throws SystemException {
3046 return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
3047 QueryUtil.ALL_POS, null);
3048 }
3049
3050
3064 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
3065 int start, int end) throws SystemException {
3066 return filterFindByG_NotC(groupId, categoryId, start, end, null);
3067 }
3068
3069
3084 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
3085 int start, int end, OrderByComparator orderByComparator)
3086 throws SystemException {
3087 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3088 return findByG_NotC(groupId, categoryId, start, end,
3089 orderByComparator);
3090 }
3091
3092 StringBundler query = null;
3093
3094 if (orderByComparator != null) {
3095 query = new StringBundler(4 +
3096 (orderByComparator.getOrderByFields().length * 3));
3097 }
3098 else {
3099 query = new StringBundler(4);
3100 }
3101
3102 if (getDB().isSupportsInlineDistinct()) {
3103 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3104 }
3105 else {
3106 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3107 }
3108
3109 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3110
3111 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3112
3113 if (!getDB().isSupportsInlineDistinct()) {
3114 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3115 }
3116
3117 if (orderByComparator != null) {
3118 if (getDB().isSupportsInlineDistinct()) {
3119 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3120 orderByComparator);
3121 }
3122 else {
3123 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3124 orderByComparator);
3125 }
3126 }
3127
3128 else {
3129 if (getDB().isSupportsInlineDistinct()) {
3130 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3131 }
3132 else {
3133 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3134 }
3135 }
3136
3137 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3138 MBThread.class.getName(),
3139 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3140
3141 Session session = null;
3142
3143 try {
3144 session = openSession();
3145
3146 SQLQuery q = session.createSQLQuery(sql);
3147
3148 if (getDB().isSupportsInlineDistinct()) {
3149 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3150 }
3151 else {
3152 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3153 }
3154
3155 QueryPos qPos = QueryPos.getInstance(q);
3156
3157 qPos.add(groupId);
3158
3159 qPos.add(categoryId);
3160
3161 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3162 }
3163 catch (Exception e) {
3164 throw processException(e);
3165 }
3166 finally {
3167 closeSession(session);
3168 }
3169 }
3170
3171
3182 public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
3183 long groupId, long categoryId, OrderByComparator orderByComparator)
3184 throws NoSuchThreadException, SystemException {
3185 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3186 return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
3187 orderByComparator);
3188 }
3189
3190 MBThread mbThread = findByPrimaryKey(threadId);
3191
3192 Session session = null;
3193
3194 try {
3195 session = openSession();
3196
3197 MBThread[] array = new MBThreadImpl[3];
3198
3199 array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
3200 groupId, categoryId, orderByComparator, true);
3201
3202 array[1] = mbThread;
3203
3204 array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
3205 groupId, categoryId, orderByComparator, false);
3206
3207 return array;
3208 }
3209 catch (Exception e) {
3210 throw processException(e);
3211 }
3212 finally {
3213 closeSession(session);
3214 }
3215 }
3216
3217 protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
3218 MBThread mbThread, long groupId, long categoryId,
3219 OrderByComparator orderByComparator, boolean previous) {
3220 StringBundler query = null;
3221
3222 if (orderByComparator != null) {
3223 query = new StringBundler(6 +
3224 (orderByComparator.getOrderByFields().length * 6));
3225 }
3226 else {
3227 query = new StringBundler(3);
3228 }
3229
3230 if (getDB().isSupportsInlineDistinct()) {
3231 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3232 }
3233 else {
3234 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3235 }
3236
3237 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3238
3239 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3240
3241 if (!getDB().isSupportsInlineDistinct()) {
3242 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3243 }
3244
3245 if (orderByComparator != null) {
3246 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3247
3248 if (orderByConditionFields.length > 0) {
3249 query.append(WHERE_AND);
3250 }
3251
3252 for (int i = 0; i < orderByConditionFields.length; i++) {
3253 if (getDB().isSupportsInlineDistinct()) {
3254 query.append(_ORDER_BY_ENTITY_ALIAS);
3255 }
3256 else {
3257 query.append(_ORDER_BY_ENTITY_TABLE);
3258 }
3259
3260 query.append(orderByConditionFields[i]);
3261
3262 if ((i + 1) < orderByConditionFields.length) {
3263 if (orderByComparator.isAscending() ^ previous) {
3264 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3265 }
3266 else {
3267 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3268 }
3269 }
3270 else {
3271 if (orderByComparator.isAscending() ^ previous) {
3272 query.append(WHERE_GREATER_THAN);
3273 }
3274 else {
3275 query.append(WHERE_LESSER_THAN);
3276 }
3277 }
3278 }
3279
3280 query.append(ORDER_BY_CLAUSE);
3281
3282 String[] orderByFields = orderByComparator.getOrderByFields();
3283
3284 for (int i = 0; i < orderByFields.length; i++) {
3285 if (getDB().isSupportsInlineDistinct()) {
3286 query.append(_ORDER_BY_ENTITY_ALIAS);
3287 }
3288 else {
3289 query.append(_ORDER_BY_ENTITY_TABLE);
3290 }
3291
3292 query.append(orderByFields[i]);
3293
3294 if ((i + 1) < orderByFields.length) {
3295 if (orderByComparator.isAscending() ^ previous) {
3296 query.append(ORDER_BY_ASC_HAS_NEXT);
3297 }
3298 else {
3299 query.append(ORDER_BY_DESC_HAS_NEXT);
3300 }
3301 }
3302 else {
3303 if (orderByComparator.isAscending() ^ previous) {
3304 query.append(ORDER_BY_ASC);
3305 }
3306 else {
3307 query.append(ORDER_BY_DESC);
3308 }
3309 }
3310 }
3311 }
3312
3313 else {
3314 if (getDB().isSupportsInlineDistinct()) {
3315 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3316 }
3317 else {
3318 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3319 }
3320 }
3321
3322 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3323 MBThread.class.getName(),
3324 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3325
3326 SQLQuery q = session.createSQLQuery(sql);
3327
3328 q.setFirstResult(0);
3329 q.setMaxResults(2);
3330
3331 if (getDB().isSupportsInlineDistinct()) {
3332 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3333 }
3334 else {
3335 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3336 }
3337
3338 QueryPos qPos = QueryPos.getInstance(q);
3339
3340 qPos.add(groupId);
3341
3342 qPos.add(categoryId);
3343
3344 if (orderByComparator != null) {
3345 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3346
3347 for (Object value : values) {
3348 qPos.add(value);
3349 }
3350 }
3351
3352 List<MBThread> list = q.list();
3353
3354 if (list.size() == 2) {
3355 return list.get(1);
3356 }
3357 else {
3358 return null;
3359 }
3360 }
3361
3362
3370 public List<MBThread> findByG_S(long groupId, int status)
3371 throws SystemException {
3372 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3373 null);
3374 }
3375
3376
3390 public List<MBThread> findByG_S(long groupId, int status, int start, int end)
3391 throws SystemException {
3392 return findByG_S(groupId, status, start, end, null);
3393 }
3394
3395
3410 public List<MBThread> findByG_S(long groupId, int status, int start,
3411 int end, OrderByComparator orderByComparator) throws SystemException {
3412 FinderPath finderPath = null;
3413 Object[] finderArgs = null;
3414
3415 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3416 (orderByComparator == null)) {
3417 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
3418 finderArgs = new Object[] { groupId, status };
3419 }
3420 else {
3421 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
3422 finderArgs = new Object[] {
3423 groupId, status,
3424
3425 start, end, orderByComparator
3426 };
3427 }
3428
3429 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
3430 finderArgs, this);
3431
3432 if (list == null) {
3433 StringBundler query = null;
3434
3435 if (orderByComparator != null) {
3436 query = new StringBundler(4 +
3437 (orderByComparator.getOrderByFields().length * 3));
3438 }
3439 else {
3440 query = new StringBundler(4);
3441 }
3442
3443 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3444
3445 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3446
3447 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3448
3449 if (orderByComparator != null) {
3450 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3451 orderByComparator);
3452 }
3453
3454 else {
3455 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3456 }
3457
3458 String sql = query.toString();
3459
3460 Session session = null;
3461
3462 try {
3463 session = openSession();
3464
3465 Query q = session.createQuery(sql);
3466
3467 QueryPos qPos = QueryPos.getInstance(q);
3468
3469 qPos.add(groupId);
3470
3471 qPos.add(status);
3472
3473 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
3474 end);
3475 }
3476 catch (Exception e) {
3477 throw processException(e);
3478 }
3479 finally {
3480 if (list == null) {
3481 FinderCacheUtil.removeResult(finderPath, finderArgs);
3482 }
3483 else {
3484 cacheResult(list);
3485
3486 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3487 }
3488
3489 closeSession(session);
3490 }
3491 }
3492
3493 return list;
3494 }
3495
3496
3510 public MBThread findByG_S_First(long groupId, int status,
3511 OrderByComparator orderByComparator)
3512 throws NoSuchThreadException, SystemException {
3513 List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
3514
3515 if (list.isEmpty()) {
3516 StringBundler msg = new StringBundler(6);
3517
3518 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3519
3520 msg.append("groupId=");
3521 msg.append(groupId);
3522
3523 msg.append(", status=");
3524 msg.append(status);
3525
3526 msg.append(StringPool.CLOSE_CURLY_BRACE);
3527
3528 throw new NoSuchThreadException(msg.toString());
3529 }
3530 else {
3531 return list.get(0);
3532 }
3533 }
3534
3535
3549 public MBThread findByG_S_Last(long groupId, int status,
3550 OrderByComparator orderByComparator)
3551 throws NoSuchThreadException, SystemException {
3552 int count = countByG_S(groupId, status);
3553
3554 List<MBThread> list = findByG_S(groupId, status, count - 1, count,
3555 orderByComparator);
3556
3557 if (list.isEmpty()) {
3558 StringBundler msg = new StringBundler(6);
3559
3560 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3561
3562 msg.append("groupId=");
3563 msg.append(groupId);
3564
3565 msg.append(", status=");
3566 msg.append(status);
3567
3568 msg.append(StringPool.CLOSE_CURLY_BRACE);
3569
3570 throw new NoSuchThreadException(msg.toString());
3571 }
3572 else {
3573 return list.get(0);
3574 }
3575 }
3576
3577
3592 public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
3593 int status, OrderByComparator orderByComparator)
3594 throws NoSuchThreadException, SystemException {
3595 MBThread mbThread = findByPrimaryKey(threadId);
3596
3597 Session session = null;
3598
3599 try {
3600 session = openSession();
3601
3602 MBThread[] array = new MBThreadImpl[3];
3603
3604 array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
3605 orderByComparator, true);
3606
3607 array[1] = mbThread;
3608
3609 array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
3610 orderByComparator, false);
3611
3612 return array;
3613 }
3614 catch (Exception e) {
3615 throw processException(e);
3616 }
3617 finally {
3618 closeSession(session);
3619 }
3620 }
3621
3622 protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
3623 long groupId, int status, OrderByComparator orderByComparator,
3624 boolean previous) {
3625 StringBundler query = null;
3626
3627 if (orderByComparator != null) {
3628 query = new StringBundler(6 +
3629 (orderByComparator.getOrderByFields().length * 6));
3630 }
3631 else {
3632 query = new StringBundler(3);
3633 }
3634
3635 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3636
3637 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3638
3639 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3640
3641 if (orderByComparator != null) {
3642 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3643
3644 if (orderByConditionFields.length > 0) {
3645 query.append(WHERE_AND);
3646 }
3647
3648 for (int i = 0; i < orderByConditionFields.length; i++) {
3649 query.append(_ORDER_BY_ENTITY_ALIAS);
3650 query.append(orderByConditionFields[i]);
3651
3652 if ((i + 1) < orderByConditionFields.length) {
3653 if (orderByComparator.isAscending() ^ previous) {
3654 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3655 }
3656 else {
3657 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3658 }
3659 }
3660 else {
3661 if (orderByComparator.isAscending() ^ previous) {
3662 query.append(WHERE_GREATER_THAN);
3663 }
3664 else {
3665 query.append(WHERE_LESSER_THAN);
3666 }
3667 }
3668 }
3669
3670 query.append(ORDER_BY_CLAUSE);
3671
3672 String[] orderByFields = orderByComparator.getOrderByFields();
3673
3674 for (int i = 0; i < orderByFields.length; i++) {
3675 query.append(_ORDER_BY_ENTITY_ALIAS);
3676 query.append(orderByFields[i]);
3677
3678 if ((i + 1) < orderByFields.length) {
3679 if (orderByComparator.isAscending() ^ previous) {
3680 query.append(ORDER_BY_ASC_HAS_NEXT);
3681 }
3682 else {
3683 query.append(ORDER_BY_DESC_HAS_NEXT);
3684 }
3685 }
3686 else {
3687 if (orderByComparator.isAscending() ^ previous) {
3688 query.append(ORDER_BY_ASC);
3689 }
3690 else {
3691 query.append(ORDER_BY_DESC);
3692 }
3693 }
3694 }
3695 }
3696
3697 else {
3698 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3699 }
3700
3701 String sql = query.toString();
3702
3703 Query q = session.createQuery(sql);
3704
3705 q.setFirstResult(0);
3706 q.setMaxResults(2);
3707
3708 QueryPos qPos = QueryPos.getInstance(q);
3709
3710 qPos.add(groupId);
3711
3712 qPos.add(status);
3713
3714 if (orderByComparator != null) {
3715 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3716
3717 for (Object value : values) {
3718 qPos.add(value);
3719 }
3720 }
3721
3722 List<MBThread> list = q.list();
3723
3724 if (list.size() == 2) {
3725 return list.get(1);
3726 }
3727 else {
3728 return null;
3729 }
3730 }
3731
3732
3740 public List<MBThread> filterFindByG_S(long groupId, int status)
3741 throws SystemException {
3742 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
3743 QueryUtil.ALL_POS, null);
3744 }
3745
3746
3760 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
3761 int end) throws SystemException {
3762 return filterFindByG_S(groupId, status, start, end, null);
3763 }
3764
3765
3780 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
3781 int end, OrderByComparator orderByComparator) throws SystemException {
3782 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3783 return findByG_S(groupId, status, start, end, orderByComparator);
3784 }
3785
3786 StringBundler query = null;
3787
3788 if (orderByComparator != null) {
3789 query = new StringBundler(4 +
3790 (orderByComparator.getOrderByFields().length * 3));
3791 }
3792 else {
3793 query = new StringBundler(4);
3794 }
3795
3796 if (getDB().isSupportsInlineDistinct()) {
3797 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3798 }
3799 else {
3800 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3801 }
3802
3803 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3804
3805 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3806
3807 if (!getDB().isSupportsInlineDistinct()) {
3808 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3809 }
3810
3811 if (orderByComparator != null) {
3812 if (getDB().isSupportsInlineDistinct()) {
3813 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3814 orderByComparator);
3815 }
3816 else {
3817 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3818 orderByComparator);
3819 }
3820 }
3821
3822 else {
3823 if (getDB().isSupportsInlineDistinct()) {
3824 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3825 }
3826 else {
3827 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3828 }
3829 }
3830
3831 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3832 MBThread.class.getName(),
3833 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3834
3835 Session session = null;
3836
3837 try {
3838 session = openSession();
3839
3840 SQLQuery q = session.createSQLQuery(sql);
3841
3842 if (getDB().isSupportsInlineDistinct()) {
3843 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3844 }
3845 else {
3846 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3847 }
3848
3849 QueryPos qPos = QueryPos.getInstance(q);
3850
3851 qPos.add(groupId);
3852
3853 qPos.add(status);
3854
3855 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3856 }
3857 catch (Exception e) {
3858 throw processException(e);
3859 }
3860 finally {
3861 closeSession(session);
3862 }
3863 }
3864
3865
3876 public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
3877 int status, OrderByComparator orderByComparator)
3878 throws NoSuchThreadException, SystemException {
3879 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3880 return findByG_S_PrevAndNext(threadId, groupId, status,
3881 orderByComparator);
3882 }
3883
3884 MBThread mbThread = findByPrimaryKey(threadId);
3885
3886 Session session = null;
3887
3888 try {
3889 session = openSession();
3890
3891 MBThread[] array = new MBThreadImpl[3];
3892
3893 array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
3894 status, orderByComparator, true);
3895
3896 array[1] = mbThread;
3897
3898 array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
3899 status, orderByComparator, false);
3900
3901 return array;
3902 }
3903 catch (Exception e) {
3904 throw processException(e);
3905 }
3906 finally {
3907 closeSession(session);
3908 }
3909 }
3910
3911 protected MBThread filterGetByG_S_PrevAndNext(Session session,
3912 MBThread mbThread, long groupId, int status,
3913 OrderByComparator orderByComparator, boolean previous) {
3914 StringBundler query = null;
3915
3916 if (orderByComparator != null) {
3917 query = new StringBundler(6 +
3918 (orderByComparator.getOrderByFields().length * 6));
3919 }
3920 else {
3921 query = new StringBundler(3);
3922 }
3923
3924 if (getDB().isSupportsInlineDistinct()) {
3925 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3926 }
3927 else {
3928 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3929 }
3930
3931 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3932
3933 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3934
3935 if (!getDB().isSupportsInlineDistinct()) {
3936 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3937 }
3938
3939 if (orderByComparator != null) {
3940 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3941
3942 if (orderByConditionFields.length > 0) {
3943 query.append(WHERE_AND);
3944 }
3945
3946 for (int i = 0; i < orderByConditionFields.length; i++) {
3947 if (getDB().isSupportsInlineDistinct()) {
3948 query.append(_ORDER_BY_ENTITY_ALIAS);
3949 }
3950 else {
3951 query.append(_ORDER_BY_ENTITY_TABLE);
3952 }
3953
3954 query.append(orderByConditionFields[i]);
3955
3956 if ((i + 1) < orderByConditionFields.length) {
3957 if (orderByComparator.isAscending() ^ previous) {
3958 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3959 }
3960 else {
3961 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3962 }
3963 }
3964 else {
3965 if (orderByComparator.isAscending() ^ previous) {
3966 query.append(WHERE_GREATER_THAN);
3967 }
3968 else {
3969 query.append(WHERE_LESSER_THAN);
3970 }
3971 }
3972 }
3973
3974 query.append(ORDER_BY_CLAUSE);
3975
3976 String[] orderByFields = orderByComparator.getOrderByFields();
3977
3978 for (int i = 0; i < orderByFields.length; i++) {
3979 if (getDB().isSupportsInlineDistinct()) {
3980 query.append(_ORDER_BY_ENTITY_ALIAS);
3981 }
3982 else {
3983 query.append(_ORDER_BY_ENTITY_TABLE);
3984 }
3985
3986 query.append(orderByFields[i]);
3987
3988 if ((i + 1) < orderByFields.length) {
3989 if (orderByComparator.isAscending() ^ previous) {
3990 query.append(ORDER_BY_ASC_HAS_NEXT);
3991 }
3992 else {
3993 query.append(ORDER_BY_DESC_HAS_NEXT);
3994 }
3995 }
3996 else {
3997 if (orderByComparator.isAscending() ^ previous) {
3998 query.append(ORDER_BY_ASC);
3999 }
4000 else {
4001 query.append(ORDER_BY_DESC);
4002 }
4003 }
4004 }
4005 }
4006
4007 else {
4008 if (getDB().isSupportsInlineDistinct()) {
4009 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4010 }
4011 else {
4012 query.append(MBThreadModelImpl.ORDER_BY_SQL);
4013 }
4014 }
4015
4016 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4017 MBThread.class.getName(),
4018 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4019
4020 SQLQuery q = session.createSQLQuery(sql);
4021
4022 q.setFirstResult(0);
4023 q.setMaxResults(2);
4024
4025 if (getDB().isSupportsInlineDistinct()) {
4026 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4027 }
4028 else {
4029 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4030 }
4031
4032 QueryPos qPos = QueryPos.getInstance(q);
4033
4034 qPos.add(groupId);
4035
4036 qPos.add(status);
4037
4038 if (orderByComparator != null) {
4039 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4040
4041 for (Object value : values) {
4042 qPos.add(value);
4043 }
4044 }
4045
4046 List<MBThread> list = q.list();
4047
4048 if (list.size() == 2) {
4049 return list.get(1);
4050 }
4051 else {
4052 return null;
4053 }
4054 }
4055
4056
4064 public List<MBThread> findByC_P(long categoryId, double priority)
4065 throws SystemException {
4066 return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
4067 QueryUtil.ALL_POS, null);
4068 }
4069
4070
4084 public List<MBThread> findByC_P(long categoryId, double priority,
4085 int start, int end) throws SystemException {
4086 return findByC_P(categoryId, priority, start, end, null);
4087 }
4088
4089
4104 public List<MBThread> findByC_P(long categoryId, double priority,
4105 int start, int end, OrderByComparator orderByComparator)
4106 throws SystemException {
4107 FinderPath finderPath = null;
4108 Object[] finderArgs = null;
4109
4110 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4111 (orderByComparator == null)) {
4112 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
4113 finderArgs = new Object[] { categoryId, priority };
4114 }
4115 else {
4116 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
4117 finderArgs = new Object[] {
4118 categoryId, priority,
4119
4120 start, end, orderByComparator
4121 };
4122 }
4123
4124 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4125 finderArgs, this);
4126
4127 if (list == null) {
4128 StringBundler query = null;
4129
4130 if (orderByComparator != null) {
4131 query = new StringBundler(4 +
4132 (orderByComparator.getOrderByFields().length * 3));
4133 }
4134 else {
4135 query = new StringBundler(4);
4136 }
4137
4138 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4139
4140 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4141
4142 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4143
4144 if (orderByComparator != null) {
4145 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4146 orderByComparator);
4147 }
4148
4149 else {
4150 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4151 }
4152
4153 String sql = query.toString();
4154
4155 Session session = null;
4156
4157 try {
4158 session = openSession();
4159
4160 Query q = session.createQuery(sql);
4161
4162 QueryPos qPos = QueryPos.getInstance(q);
4163
4164 qPos.add(categoryId);
4165
4166 qPos.add(priority);
4167
4168 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
4169 end);
4170 }
4171 catch (Exception e) {
4172 throw processException(e);
4173 }
4174 finally {
4175 if (list == null) {
4176 FinderCacheUtil.removeResult(finderPath, finderArgs);
4177 }
4178 else {
4179 cacheResult(list);
4180
4181 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4182 }
4183
4184 closeSession(session);
4185 }
4186 }
4187
4188 return list;
4189 }
4190
4191
4205 public MBThread findByC_P_First(long categoryId, double priority,
4206 OrderByComparator orderByComparator)
4207 throws NoSuchThreadException, SystemException {
4208 List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
4209 orderByComparator);
4210
4211 if (list.isEmpty()) {
4212 StringBundler msg = new StringBundler(6);
4213
4214 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4215
4216 msg.append("categoryId=");
4217 msg.append(categoryId);
4218
4219 msg.append(", priority=");
4220 msg.append(priority);
4221
4222 msg.append(StringPool.CLOSE_CURLY_BRACE);
4223
4224 throw new NoSuchThreadException(msg.toString());
4225 }
4226 else {
4227 return list.get(0);
4228 }
4229 }
4230
4231
4245 public MBThread findByC_P_Last(long categoryId, double priority,
4246 OrderByComparator orderByComparator)
4247 throws NoSuchThreadException, SystemException {
4248 int count = countByC_P(categoryId, priority);
4249
4250 List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
4251 orderByComparator);
4252
4253 if (list.isEmpty()) {
4254 StringBundler msg = new StringBundler(6);
4255
4256 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4257
4258 msg.append("categoryId=");
4259 msg.append(categoryId);
4260
4261 msg.append(", priority=");
4262 msg.append(priority);
4263
4264 msg.append(StringPool.CLOSE_CURLY_BRACE);
4265
4266 throw new NoSuchThreadException(msg.toString());
4267 }
4268 else {
4269 return list.get(0);
4270 }
4271 }
4272
4273
4288 public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
4289 double priority, OrderByComparator orderByComparator)
4290 throws NoSuchThreadException, SystemException {
4291 MBThread mbThread = findByPrimaryKey(threadId);
4292
4293 Session session = null;
4294
4295 try {
4296 session = openSession();
4297
4298 MBThread[] array = new MBThreadImpl[3];
4299
4300 array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
4301 priority, orderByComparator, true);
4302
4303 array[1] = mbThread;
4304
4305 array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
4306 priority, orderByComparator, false);
4307
4308 return array;
4309 }
4310 catch (Exception e) {
4311 throw processException(e);
4312 }
4313 finally {
4314 closeSession(session);
4315 }
4316 }
4317
4318 protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
4319 long categoryId, double priority, OrderByComparator orderByComparator,
4320 boolean previous) {
4321 StringBundler query = null;
4322
4323 if (orderByComparator != null) {
4324 query = new StringBundler(6 +
4325 (orderByComparator.getOrderByFields().length * 6));
4326 }
4327 else {
4328 query = new StringBundler(3);
4329 }
4330
4331 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4332
4333 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4334
4335 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4336
4337 if (orderByComparator != null) {
4338 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4339
4340 if (orderByConditionFields.length > 0) {
4341 query.append(WHERE_AND);
4342 }
4343
4344 for (int i = 0; i < orderByConditionFields.length; i++) {
4345 query.append(_ORDER_BY_ENTITY_ALIAS);
4346 query.append(orderByConditionFields[i]);
4347
4348 if ((i + 1) < orderByConditionFields.length) {
4349 if (orderByComparator.isAscending() ^ previous) {
4350 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4351 }
4352 else {
4353 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4354 }
4355 }
4356 else {
4357 if (orderByComparator.isAscending() ^ previous) {
4358 query.append(WHERE_GREATER_THAN);
4359 }
4360 else {
4361 query.append(WHERE_LESSER_THAN);
4362 }
4363 }
4364 }
4365
4366 query.append(ORDER_BY_CLAUSE);
4367
4368 String[] orderByFields = orderByComparator.getOrderByFields();
4369
4370 for (int i = 0; i < orderByFields.length; i++) {
4371 query.append(_ORDER_BY_ENTITY_ALIAS);
4372 query.append(orderByFields[i]);
4373
4374 if ((i + 1) < orderByFields.length) {
4375 if (orderByComparator.isAscending() ^ previous) {
4376 query.append(ORDER_BY_ASC_HAS_NEXT);
4377 }
4378 else {
4379 query.append(ORDER_BY_DESC_HAS_NEXT);
4380 }
4381 }
4382 else {
4383 if (orderByComparator.isAscending() ^ previous) {
4384 query.append(ORDER_BY_ASC);
4385 }
4386 else {
4387 query.append(ORDER_BY_DESC);
4388 }
4389 }
4390 }
4391 }
4392
4393 else {
4394 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4395 }
4396
4397 String sql = query.toString();
4398
4399 Query q = session.createQuery(sql);
4400
4401 q.setFirstResult(0);
4402 q.setMaxResults(2);
4403
4404 QueryPos qPos = QueryPos.getInstance(q);
4405
4406 qPos.add(categoryId);
4407
4408 qPos.add(priority);
4409
4410 if (orderByComparator != null) {
4411 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4412
4413 for (Object value : values) {
4414 qPos.add(value);
4415 }
4416 }
4417
4418 List<MBThread> list = q.list();
4419
4420 if (list.size() == 2) {
4421 return list.get(1);
4422 }
4423 else {
4424 return null;
4425 }
4426 }
4427
4428
4436 public List<MBThread> findByL_P(Date lastPostDate, double priority)
4437 throws SystemException {
4438 return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
4439 QueryUtil.ALL_POS, null);
4440 }
4441
4442
4456 public List<MBThread> findByL_P(Date lastPostDate, double priority,
4457 int start, int end) throws SystemException {
4458 return findByL_P(lastPostDate, priority, start, end, null);
4459 }
4460
4461
4476 public List<MBThread> findByL_P(Date lastPostDate, double priority,
4477 int start, int end, OrderByComparator orderByComparator)
4478 throws SystemException {
4479 FinderPath finderPath = null;
4480 Object[] finderArgs = null;
4481
4482 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4483 (orderByComparator == null)) {
4484 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
4485 finderArgs = new Object[] { lastPostDate, priority };
4486 }
4487 else {
4488 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
4489 finderArgs = new Object[] {
4490 lastPostDate, priority,
4491
4492 start, end, orderByComparator
4493 };
4494 }
4495
4496 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4497 finderArgs, this);
4498
4499 if (list == null) {
4500 StringBundler query = null;
4501
4502 if (orderByComparator != null) {
4503 query = new StringBundler(4 +
4504 (orderByComparator.getOrderByFields().length * 3));
4505 }
4506 else {
4507 query = new StringBundler(4);
4508 }
4509
4510 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4511
4512 if (lastPostDate == null) {
4513 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
4514 }
4515 else {
4516 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
4517 }
4518
4519 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
4520
4521 if (orderByComparator != null) {
4522 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4523 orderByComparator);
4524 }
4525
4526 else {
4527 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4528 }
4529
4530 String sql = query.toString();
4531
4532 Session session = null;
4533
4534 try {
4535 session = openSession();
4536
4537 Query q = session.createQuery(sql);
4538
4539 QueryPos qPos = QueryPos.getInstance(q);
4540
4541 if (lastPostDate != null) {
4542 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4543 }
4544
4545 qPos.add(priority);
4546
4547 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
4548 end);
4549 }
4550 catch (Exception e) {
4551 throw processException(e);
4552 }
4553 finally {
4554 if (list == null) {
4555 FinderCacheUtil.removeResult(finderPath, finderArgs);
4556 }
4557 else {
4558 cacheResult(list);
4559
4560 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4561 }
4562
4563 closeSession(session);
4564 }
4565 }
4566
4567 return list;
4568 }
4569
4570
4584 public MBThread findByL_P_First(Date lastPostDate, double priority,
4585 OrderByComparator orderByComparator)
4586 throws NoSuchThreadException, SystemException {
4587 List<MBThread> list = findByL_P(lastPostDate, priority, 0, 1,
4588 orderByComparator);
4589
4590 if (list.isEmpty()) {
4591 StringBundler msg = new StringBundler(6);
4592
4593 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4594
4595 msg.append("lastPostDate=");
4596 msg.append(lastPostDate);
4597
4598 msg.append(", priority=");
4599 msg.append(priority);
4600
4601 msg.append(StringPool.CLOSE_CURLY_BRACE);
4602
4603 throw new NoSuchThreadException(msg.toString());
4604 }
4605 else {
4606 return list.get(0);
4607 }
4608 }
4609
4610
4624 public MBThread findByL_P_Last(Date lastPostDate, double priority,
4625 OrderByComparator orderByComparator)
4626 throws NoSuchThreadException, SystemException {
4627 int count = countByL_P(lastPostDate, priority);
4628
4629 List<MBThread> list = findByL_P(lastPostDate, priority, count - 1,
4630 count, orderByComparator);
4631
4632 if (list.isEmpty()) {
4633 StringBundler msg = new StringBundler(6);
4634
4635 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4636
4637 msg.append("lastPostDate=");
4638 msg.append(lastPostDate);
4639
4640 msg.append(", priority=");
4641 msg.append(priority);
4642
4643 msg.append(StringPool.CLOSE_CURLY_BRACE);
4644
4645 throw new NoSuchThreadException(msg.toString());
4646 }
4647 else {
4648 return list.get(0);
4649 }
4650 }
4651
4652
4667 public MBThread[] findByL_P_PrevAndNext(long threadId, Date lastPostDate,
4668 double priority, OrderByComparator orderByComparator)
4669 throws NoSuchThreadException, SystemException {
4670 MBThread mbThread = findByPrimaryKey(threadId);
4671
4672 Session session = null;
4673
4674 try {
4675 session = openSession();
4676
4677 MBThread[] array = new MBThreadImpl[3];
4678
4679 array[0] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
4680 priority, orderByComparator, true);
4681
4682 array[1] = mbThread;
4683
4684 array[2] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
4685 priority, orderByComparator, false);
4686
4687 return array;
4688 }
4689 catch (Exception e) {
4690 throw processException(e);
4691 }
4692 finally {
4693 closeSession(session);
4694 }
4695 }
4696
4697 protected MBThread getByL_P_PrevAndNext(Session session, MBThread mbThread,
4698 Date lastPostDate, double priority,
4699 OrderByComparator orderByComparator, boolean previous) {
4700 StringBundler query = null;
4701
4702 if (orderByComparator != null) {
4703 query = new StringBundler(6 +
4704 (orderByComparator.getOrderByFields().length * 6));
4705 }
4706 else {
4707 query = new StringBundler(3);
4708 }
4709
4710 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4711
4712 if (lastPostDate == null) {
4713 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
4714 }
4715 else {
4716 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
4717 }
4718
4719 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
4720
4721 if (orderByComparator != null) {
4722 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4723
4724 if (orderByConditionFields.length > 0) {
4725 query.append(WHERE_AND);
4726 }
4727
4728 for (int i = 0; i < orderByConditionFields.length; i++) {
4729 query.append(_ORDER_BY_ENTITY_ALIAS);
4730 query.append(orderByConditionFields[i]);
4731
4732 if ((i + 1) < orderByConditionFields.length) {
4733 if (orderByComparator.isAscending() ^ previous) {
4734 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4735 }
4736 else {
4737 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4738 }
4739 }
4740 else {
4741 if (orderByComparator.isAscending() ^ previous) {
4742 query.append(WHERE_GREATER_THAN);
4743 }
4744 else {
4745 query.append(WHERE_LESSER_THAN);
4746 }
4747 }
4748 }
4749
4750 query.append(ORDER_BY_CLAUSE);
4751
4752 String[] orderByFields = orderByComparator.getOrderByFields();
4753
4754 for (int i = 0; i < orderByFields.length; i++) {
4755 query.append(_ORDER_BY_ENTITY_ALIAS);
4756 query.append(orderByFields[i]);
4757
4758 if ((i + 1) < orderByFields.length) {
4759 if (orderByComparator.isAscending() ^ previous) {
4760 query.append(ORDER_BY_ASC_HAS_NEXT);
4761 }
4762 else {
4763 query.append(ORDER_BY_DESC_HAS_NEXT);
4764 }
4765 }
4766 else {
4767 if (orderByComparator.isAscending() ^ previous) {
4768 query.append(ORDER_BY_ASC);
4769 }
4770 else {
4771 query.append(ORDER_BY_DESC);
4772 }
4773 }
4774 }
4775 }
4776
4777 else {
4778 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4779 }
4780
4781 String sql = query.toString();
4782
4783 Query q = session.createQuery(sql);
4784
4785 q.setFirstResult(0);
4786 q.setMaxResults(2);
4787
4788 QueryPos qPos = QueryPos.getInstance(q);
4789
4790 if (lastPostDate != null) {
4791 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4792 }
4793
4794 qPos.add(priority);
4795
4796 if (orderByComparator != null) {
4797 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4798
4799 for (Object value : values) {
4800 qPos.add(value);
4801 }
4802 }
4803
4804 List<MBThread> list = q.list();
4805
4806 if (list.size() == 2) {
4807 return list.get(1);
4808 }
4809 else {
4810 return null;
4811 }
4812 }
4813
4814
4823 public List<MBThread> findByG_C_L(long groupId, long categoryId,
4824 Date lastPostDate) throws SystemException {
4825 return findByG_C_L(groupId, categoryId, lastPostDate,
4826 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4827 }
4828
4829
4844 public List<MBThread> findByG_C_L(long groupId, long categoryId,
4845 Date lastPostDate, int start, int end) throws SystemException {
4846 return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
4847 }
4848
4849
4865 public List<MBThread> findByG_C_L(long groupId, long categoryId,
4866 Date lastPostDate, int start, int end,
4867 OrderByComparator orderByComparator) throws SystemException {
4868 FinderPath finderPath = null;
4869 Object[] finderArgs = null;
4870
4871 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4872 (orderByComparator == null)) {
4873 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
4874 finderArgs = new Object[] { groupId, categoryId, lastPostDate };
4875 }
4876 else {
4877 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
4878 finderArgs = new Object[] {
4879 groupId, categoryId, lastPostDate,
4880
4881 start, end, orderByComparator
4882 };
4883 }
4884
4885 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4886 finderArgs, this);
4887
4888 if (list == null) {
4889 StringBundler query = null;
4890
4891 if (orderByComparator != null) {
4892 query = new StringBundler(5 +
4893 (orderByComparator.getOrderByFields().length * 3));
4894 }
4895 else {
4896 query = new StringBundler(5);
4897 }
4898
4899 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4900
4901 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
4902
4903 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
4904
4905 if (lastPostDate == null) {
4906 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
4907 }
4908 else {
4909 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
4910 }
4911
4912 if (orderByComparator != null) {
4913 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4914 orderByComparator);
4915 }
4916
4917 else {
4918 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4919 }
4920
4921 String sql = query.toString();
4922
4923 Session session = null;
4924
4925 try {
4926 session = openSession();
4927
4928 Query q = session.createQuery(sql);
4929
4930 QueryPos qPos = QueryPos.getInstance(q);
4931
4932 qPos.add(groupId);
4933
4934 qPos.add(categoryId);
4935
4936 if (lastPostDate != null) {
4937 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4938 }
4939
4940 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
4941 end);
4942 }
4943 catch (Exception e) {
4944 throw processException(e);
4945 }
4946 finally {
4947 if (list == null) {
4948 FinderCacheUtil.removeResult(finderPath, finderArgs);
4949 }
4950 else {
4951 cacheResult(list);
4952
4953 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4954 }
4955
4956 closeSession(session);
4957 }
4958 }
4959
4960 return list;
4961 }
4962
4963
4978 public MBThread findByG_C_L_First(long groupId, long categoryId,
4979 Date lastPostDate, OrderByComparator orderByComparator)
4980 throws NoSuchThreadException, SystemException {
4981 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
4982 1, orderByComparator);
4983
4984 if (list.isEmpty()) {
4985 StringBundler msg = new StringBundler(8);
4986
4987 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4988
4989 msg.append("groupId=");
4990 msg.append(groupId);
4991
4992 msg.append(", categoryId=");
4993 msg.append(categoryId);
4994
4995 msg.append(", lastPostDate=");
4996 msg.append(lastPostDate);
4997
4998 msg.append(StringPool.CLOSE_CURLY_BRACE);
4999
5000 throw new NoSuchThreadException(msg.toString());
5001 }
5002 else {
5003 return list.get(0);
5004 }
5005 }
5006
5007
5022 public MBThread findByG_C_L_Last(long groupId, long categoryId,
5023 Date lastPostDate, OrderByComparator orderByComparator)
5024 throws NoSuchThreadException, SystemException {
5025 int count = countByG_C_L(groupId, categoryId, lastPostDate);
5026
5027 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
5028 count - 1, count, orderByComparator);
5029
5030 if (list.isEmpty()) {
5031 StringBundler msg = new StringBundler(8);
5032
5033 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5034
5035 msg.append("groupId=");
5036 msg.append(groupId);
5037
5038 msg.append(", categoryId=");
5039 msg.append(categoryId);
5040
5041 msg.append(", lastPostDate=");
5042 msg.append(lastPostDate);
5043
5044 msg.append(StringPool.CLOSE_CURLY_BRACE);
5045
5046 throw new NoSuchThreadException(msg.toString());
5047 }
5048 else {
5049 return list.get(0);
5050 }
5051 }
5052
5053
5069 public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
5070 long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
5071 throws NoSuchThreadException, SystemException {
5072 MBThread mbThread = findByPrimaryKey(threadId);
5073
5074 Session session = null;
5075
5076 try {
5077 session = openSession();
5078
5079 MBThread[] array = new MBThreadImpl[3];
5080
5081 array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
5082 categoryId, lastPostDate, orderByComparator, true);
5083
5084 array[1] = mbThread;
5085
5086 array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
5087 categoryId, lastPostDate, orderByComparator, false);
5088
5089 return array;
5090 }
5091 catch (Exception e) {
5092 throw processException(e);
5093 }
5094 finally {
5095 closeSession(session);
5096 }
5097 }
5098
5099 protected MBThread getByG_C_L_PrevAndNext(Session session,
5100 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
5101 OrderByComparator orderByComparator, boolean previous) {
5102 StringBundler query = null;
5103
5104 if (orderByComparator != null) {
5105 query = new StringBundler(6 +
5106 (orderByComparator.getOrderByFields().length * 6));
5107 }
5108 else {
5109 query = new StringBundler(3);
5110 }
5111
5112 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5113
5114 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5115
5116 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5117
5118 if (lastPostDate == null) {
5119 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5120 }
5121 else {
5122 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5123 }
5124
5125 if (orderByComparator != null) {
5126 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5127
5128 if (orderByConditionFields.length > 0) {
5129 query.append(WHERE_AND);
5130 }
5131
5132 for (int i = 0; i < orderByConditionFields.length; i++) {
5133 query.append(_ORDER_BY_ENTITY_ALIAS);
5134 query.append(orderByConditionFields[i]);
5135
5136 if ((i + 1) < orderByConditionFields.length) {
5137 if (orderByComparator.isAscending() ^ previous) {
5138 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5139 }
5140 else {
5141 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5142 }
5143 }
5144 else {
5145 if (orderByComparator.isAscending() ^ previous) {
5146 query.append(WHERE_GREATER_THAN);
5147 }
5148 else {
5149 query.append(WHERE_LESSER_THAN);
5150 }
5151 }
5152 }
5153
5154 query.append(ORDER_BY_CLAUSE);
5155
5156 String[] orderByFields = orderByComparator.getOrderByFields();
5157
5158 for (int i = 0; i < orderByFields.length; i++) {
5159 query.append(_ORDER_BY_ENTITY_ALIAS);
5160 query.append(orderByFields[i]);
5161
5162 if ((i + 1) < orderByFields.length) {
5163 if (orderByComparator.isAscending() ^ previous) {
5164 query.append(ORDER_BY_ASC_HAS_NEXT);
5165 }
5166 else {
5167 query.append(ORDER_BY_DESC_HAS_NEXT);
5168 }
5169 }
5170 else {
5171 if (orderByComparator.isAscending() ^ previous) {
5172 query.append(ORDER_BY_ASC);
5173 }
5174 else {
5175 query.append(ORDER_BY_DESC);
5176 }
5177 }
5178 }
5179 }
5180
5181 else {
5182 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5183 }
5184
5185 String sql = query.toString();
5186
5187 Query q = session.createQuery(sql);
5188
5189 q.setFirstResult(0);
5190 q.setMaxResults(2);
5191
5192 QueryPos qPos = QueryPos.getInstance(q);
5193
5194 qPos.add(groupId);
5195
5196 qPos.add(categoryId);
5197
5198 if (lastPostDate != null) {
5199 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5200 }
5201
5202 if (orderByComparator != null) {
5203 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5204
5205 for (Object value : values) {
5206 qPos.add(value);
5207 }
5208 }
5209
5210 List<MBThread> list = q.list();
5211
5212 if (list.size() == 2) {
5213 return list.get(1);
5214 }
5215 else {
5216 return null;
5217 }
5218 }
5219
5220
5229 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5230 Date lastPostDate) throws SystemException {
5231 return filterFindByG_C_L(groupId, categoryId, lastPostDate,
5232 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5233 }
5234
5235
5250 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5251 Date lastPostDate, int start, int end) throws SystemException {
5252 return filterFindByG_C_L(groupId, categoryId, lastPostDate, start, end,
5253 null);
5254 }
5255
5256
5272 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5273 Date lastPostDate, int start, int end,
5274 OrderByComparator orderByComparator) throws SystemException {
5275 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5276 return findByG_C_L(groupId, categoryId, lastPostDate, start, end,
5277 orderByComparator);
5278 }
5279
5280 StringBundler query = null;
5281
5282 if (orderByComparator != null) {
5283 query = new StringBundler(5 +
5284 (orderByComparator.getOrderByFields().length * 3));
5285 }
5286 else {
5287 query = new StringBundler(5);
5288 }
5289
5290 if (getDB().isSupportsInlineDistinct()) {
5291 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5292 }
5293 else {
5294 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5295 }
5296
5297 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5298
5299 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5300
5301 if (lastPostDate == null) {
5302 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5303 }
5304 else {
5305 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5306 }
5307
5308 if (!getDB().isSupportsInlineDistinct()) {
5309 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5310 }
5311
5312 if (orderByComparator != null) {
5313 if (getDB().isSupportsInlineDistinct()) {
5314 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5315 orderByComparator);
5316 }
5317 else {
5318 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5319 orderByComparator);
5320 }
5321 }
5322
5323 else {
5324 if (getDB().isSupportsInlineDistinct()) {
5325 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5326 }
5327 else {
5328 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5329 }
5330 }
5331
5332 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5333 MBThread.class.getName(),
5334 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5335
5336 Session session = null;
5337
5338 try {
5339 session = openSession();
5340
5341 SQLQuery q = session.createSQLQuery(sql);
5342
5343 if (getDB().isSupportsInlineDistinct()) {
5344 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5345 }
5346 else {
5347 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5348 }
5349
5350 QueryPos qPos = QueryPos.getInstance(q);
5351
5352 qPos.add(groupId);
5353
5354 qPos.add(categoryId);
5355
5356 if (lastPostDate != null) {
5357 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5358 }
5359
5360 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5361 }
5362 catch (Exception e) {
5363 throw processException(e);
5364 }
5365 finally {
5366 closeSession(session);
5367 }
5368 }
5369
5370
5382 public MBThread[] filterFindByG_C_L_PrevAndNext(long threadId,
5383 long groupId, long categoryId, Date lastPostDate,
5384 OrderByComparator orderByComparator)
5385 throws NoSuchThreadException, SystemException {
5386 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5387 return findByG_C_L_PrevAndNext(threadId, groupId, categoryId,
5388 lastPostDate, orderByComparator);
5389 }
5390
5391 MBThread mbThread = findByPrimaryKey(threadId);
5392
5393 Session session = null;
5394
5395 try {
5396 session = openSession();
5397
5398 MBThread[] array = new MBThreadImpl[3];
5399
5400 array[0] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
5401 categoryId, lastPostDate, orderByComparator, true);
5402
5403 array[1] = mbThread;
5404
5405 array[2] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
5406 categoryId, lastPostDate, orderByComparator, false);
5407
5408 return array;
5409 }
5410 catch (Exception e) {
5411 throw processException(e);
5412 }
5413 finally {
5414 closeSession(session);
5415 }
5416 }
5417
5418 protected MBThread filterGetByG_C_L_PrevAndNext(Session session,
5419 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
5420 OrderByComparator orderByComparator, boolean previous) {
5421 StringBundler query = null;
5422
5423 if (orderByComparator != null) {
5424 query = new StringBundler(6 +
5425 (orderByComparator.getOrderByFields().length * 6));
5426 }
5427 else {
5428 query = new StringBundler(3);
5429 }
5430
5431 if (getDB().isSupportsInlineDistinct()) {
5432 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5433 }
5434 else {
5435 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5436 }
5437
5438 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5439
5440 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5441
5442 if (lastPostDate == null) {
5443 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5444 }
5445 else {
5446 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5447 }
5448
5449 if (!getDB().isSupportsInlineDistinct()) {
5450 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5451 }
5452
5453 if (orderByComparator != null) {
5454 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5455
5456 if (orderByConditionFields.length > 0) {
5457 query.append(WHERE_AND);
5458 }
5459
5460 for (int i = 0; i < orderByConditionFields.length; i++) {
5461 if (getDB().isSupportsInlineDistinct()) {
5462 query.append(_ORDER_BY_ENTITY_ALIAS);
5463 }
5464 else {
5465 query.append(_ORDER_BY_ENTITY_TABLE);
5466 }
5467
5468 query.append(orderByConditionFields[i]);
5469
5470 if ((i + 1) < orderByConditionFields.length) {
5471 if (orderByComparator.isAscending() ^ previous) {
5472 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5473 }
5474 else {
5475 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5476 }
5477 }
5478 else {
5479 if (orderByComparator.isAscending() ^ previous) {
5480 query.append(WHERE_GREATER_THAN);
5481 }
5482 else {
5483 query.append(WHERE_LESSER_THAN);
5484 }
5485 }
5486 }
5487
5488 query.append(ORDER_BY_CLAUSE);
5489
5490 String[] orderByFields = orderByComparator.getOrderByFields();
5491
5492 for (int i = 0; i < orderByFields.length; i++) {
5493 if (getDB().isSupportsInlineDistinct()) {
5494 query.append(_ORDER_BY_ENTITY_ALIAS);
5495 }
5496 else {
5497 query.append(_ORDER_BY_ENTITY_TABLE);
5498 }
5499
5500 query.append(orderByFields[i]);
5501
5502 if ((i + 1) < orderByFields.length) {
5503 if (orderByComparator.isAscending() ^ previous) {
5504 query.append(ORDER_BY_ASC_HAS_NEXT);
5505 }
5506 else {
5507 query.append(ORDER_BY_DESC_HAS_NEXT);
5508 }
5509 }
5510 else {
5511 if (orderByComparator.isAscending() ^ previous) {
5512 query.append(ORDER_BY_ASC);
5513 }
5514 else {
5515 query.append(ORDER_BY_DESC);
5516 }
5517 }
5518 }
5519 }
5520
5521 else {
5522 if (getDB().isSupportsInlineDistinct()) {
5523 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5524 }
5525 else {
5526 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5527 }
5528 }
5529
5530 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5531 MBThread.class.getName(),
5532 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5533
5534 SQLQuery q = session.createSQLQuery(sql);
5535
5536 q.setFirstResult(0);
5537 q.setMaxResults(2);
5538
5539 if (getDB().isSupportsInlineDistinct()) {
5540 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5541 }
5542 else {
5543 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5544 }
5545
5546 QueryPos qPos = QueryPos.getInstance(q);
5547
5548 qPos.add(groupId);
5549
5550 qPos.add(categoryId);
5551
5552 if (lastPostDate != null) {
5553 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5554 }
5555
5556 if (orderByComparator != null) {
5557 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5558
5559 for (Object value : values) {
5560 qPos.add(value);
5561 }
5562 }
5563
5564 List<MBThread> list = q.list();
5565
5566 if (list.size() == 2) {
5567 return list.get(1);
5568 }
5569 else {
5570 return null;
5571 }
5572 }
5573
5574
5583 public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
5584 throws SystemException {
5585 return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
5586 QueryUtil.ALL_POS, null);
5587 }
5588
5589
5604 public List<MBThread> findByG_C_S(long groupId, long categoryId,
5605 int status, int start, int end) throws SystemException {
5606 return findByG_C_S(groupId, categoryId, status, start, end, null);
5607 }
5608
5609
5625 public List<MBThread> findByG_C_S(long groupId, long categoryId,
5626 int status, int start, int end, OrderByComparator orderByComparator)
5627 throws SystemException {
5628 FinderPath finderPath = null;
5629 Object[] finderArgs = null;
5630
5631 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5632 (orderByComparator == null)) {
5633 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
5634 finderArgs = new Object[] { groupId, categoryId, status };
5635 }
5636 else {
5637 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
5638 finderArgs = new Object[] {
5639 groupId, categoryId, status,
5640
5641 start, end, orderByComparator
5642 };
5643 }
5644
5645 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5646 finderArgs, this);
5647
5648 if (list == null) {
5649 StringBundler query = null;
5650
5651 if (orderByComparator != null) {
5652 query = new StringBundler(5 +
5653 (orderByComparator.getOrderByFields().length * 3));
5654 }
5655 else {
5656 query = new StringBundler(5);
5657 }
5658
5659 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5660
5661 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
5662
5663 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
5664
5665 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
5666
5667 if (orderByComparator != null) {
5668 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5669 orderByComparator);
5670 }
5671
5672 else {
5673 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5674 }
5675
5676 String sql = query.toString();
5677
5678 Session session = null;
5679
5680 try {
5681 session = openSession();
5682
5683 Query q = session.createQuery(sql);
5684
5685 QueryPos qPos = QueryPos.getInstance(q);
5686
5687 qPos.add(groupId);
5688
5689 qPos.add(categoryId);
5690
5691 qPos.add(status);
5692
5693 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
5694 end);
5695 }
5696 catch (Exception e) {
5697 throw processException(e);
5698 }
5699 finally {
5700 if (list == null) {
5701 FinderCacheUtil.removeResult(finderPath, finderArgs);
5702 }
5703 else {
5704 cacheResult(list);
5705
5706 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5707 }
5708
5709 closeSession(session);
5710 }
5711 }
5712
5713 return list;
5714 }
5715
5716
5731 public MBThread findByG_C_S_First(long groupId, long categoryId,
5732 int status, OrderByComparator orderByComparator)
5733 throws NoSuchThreadException, SystemException {
5734 List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
5735 orderByComparator);
5736
5737 if (list.isEmpty()) {
5738 StringBundler msg = new StringBundler(8);
5739
5740 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5741
5742 msg.append("groupId=");
5743 msg.append(groupId);
5744
5745 msg.append(", categoryId=");
5746 msg.append(categoryId);
5747
5748 msg.append(", status=");
5749 msg.append(status);
5750
5751 msg.append(StringPool.CLOSE_CURLY_BRACE);
5752
5753 throw new NoSuchThreadException(msg.toString());
5754 }
5755 else {
5756 return list.get(0);
5757 }
5758 }
5759
5760
5775 public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
5776 OrderByComparator orderByComparator)
5777 throws NoSuchThreadException, SystemException {
5778 int count = countByG_C_S(groupId, categoryId, status);
5779
5780 List<MBThread> list = findByG_C_S(groupId, categoryId, status,
5781 count - 1, count, orderByComparator);
5782
5783 if (list.isEmpty()) {
5784 StringBundler msg = new StringBundler(8);
5785
5786 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5787
5788 msg.append("groupId=");
5789 msg.append(groupId);
5790
5791 msg.append(", categoryId=");
5792 msg.append(categoryId);
5793
5794 msg.append(", status=");
5795 msg.append(status);
5796
5797 msg.append(StringPool.CLOSE_CURLY_BRACE);
5798
5799 throw new NoSuchThreadException(msg.toString());
5800 }
5801 else {
5802 return list.get(0);
5803 }
5804 }
5805
5806
5822 public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
5823 long categoryId, int status, OrderByComparator orderByComparator)
5824 throws NoSuchThreadException, SystemException {
5825 MBThread mbThread = findByPrimaryKey(threadId);
5826
5827 Session session = null;
5828
5829 try {
5830 session = openSession();
5831
5832 MBThread[] array = new MBThreadImpl[3];
5833
5834 array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
5835 categoryId, status, orderByComparator, true);
5836
5837 array[1] = mbThread;
5838
5839 array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
5840 categoryId, status, orderByComparator, false);
5841
5842 return array;
5843 }
5844 catch (Exception e) {
5845 throw processException(e);
5846 }
5847 finally {
5848 closeSession(session);
5849 }
5850 }
5851
5852 protected MBThread getByG_C_S_PrevAndNext(Session session,
5853 MBThread mbThread, long groupId, long categoryId, int status,
5854 OrderByComparator orderByComparator, boolean previous) {
5855 StringBundler query = null;
5856
5857 if (orderByComparator != null) {
5858 query = new StringBundler(6 +
5859 (orderByComparator.getOrderByFields().length * 6));
5860 }
5861 else {
5862 query = new StringBundler(3);
5863 }
5864
5865 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5866
5867 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
5868
5869 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
5870
5871 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
5872
5873 if (orderByComparator != null) {
5874 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5875
5876 if (orderByConditionFields.length > 0) {
5877 query.append(WHERE_AND);
5878 }
5879
5880 for (int i = 0; i < orderByConditionFields.length; i++) {
5881 query.append(_ORDER_BY_ENTITY_ALIAS);
5882 query.append(orderByConditionFields[i]);
5883
5884 if ((i + 1) < orderByConditionFields.length) {
5885 if (orderByComparator.isAscending() ^ previous) {
5886 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5887 }
5888 else {
5889 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5890 }
5891 }
5892 else {
5893 if (orderByComparator.isAscending() ^ previous) {
5894 query.append(WHERE_GREATER_THAN);
5895 }
5896 else {
5897 query.append(WHERE_LESSER_THAN);
5898 }
5899 }
5900 }
5901
5902 query.append(ORDER_BY_CLAUSE);
5903
5904 String[] orderByFields = orderByComparator.getOrderByFields();
5905
5906 for (int i = 0; i < orderByFields.length; i++) {
5907 query.append(_ORDER_BY_ENTITY_ALIAS);
5908 query.append(orderByFields[i]);
5909
5910 if ((i + 1) < orderByFields.length) {
5911 if (orderByComparator.isAscending() ^ previous) {
5912 query.append(ORDER_BY_ASC_HAS_NEXT);
5913 }
5914 else {
5915 query.append(ORDER_BY_DESC_HAS_NEXT);
5916 }
5917 }
5918 else {
5919 if (orderByComparator.isAscending() ^ previous) {
5920 query.append(ORDER_BY_ASC);
5921 }
5922 else {
5923 query.append(ORDER_BY_DESC);
5924 }
5925 }
5926 }
5927 }
5928
5929 else {
5930 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5931 }
5932
5933 String sql = query.toString();
5934
5935 Query q = session.createQuery(sql);
5936
5937 q.setFirstResult(0);
5938 q.setMaxResults(2);
5939
5940 QueryPos qPos = QueryPos.getInstance(q);
5941
5942 qPos.add(groupId);
5943
5944 qPos.add(categoryId);
5945
5946 qPos.add(status);
5947
5948 if (orderByComparator != null) {
5949 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5950
5951 for (Object value : values) {
5952 qPos.add(value);
5953 }
5954 }
5955
5956 List<MBThread> list = q.list();
5957
5958 if (list.size() == 2) {
5959 return list.get(1);
5960 }
5961 else {
5962 return null;
5963 }
5964 }
5965
5966
5979 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
5980 int status) throws SystemException {
5981 return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
5982 QueryUtil.ALL_POS, null);
5983 }
5984
5985
6000 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
6001 int status, int start, int end) throws SystemException {
6002 return findByG_C_S(groupId, categoryIds, status, start, end, null);
6003 }
6004
6005
6021 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
6022 int status, int start, int end, OrderByComparator orderByComparator)
6023 throws SystemException {
6024 FinderPath finderPath = null;
6025 Object[] finderArgs = null;
6026
6027 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6028 (orderByComparator == null)) {
6029 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
6030 finderArgs = new Object[] {
6031 groupId, StringUtil.merge(categoryIds), status
6032 };
6033 }
6034 else {
6035 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
6036 finderArgs = new Object[] {
6037 groupId, StringUtil.merge(categoryIds), status,
6038
6039 start, end, orderByComparator
6040 };
6041 }
6042
6043 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6044 finderArgs, this);
6045
6046 if (list == null) {
6047 StringBundler query = new StringBundler();
6048
6049 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6050
6051 boolean conjunctionable = false;
6052
6053 if (conjunctionable) {
6054 query.append(WHERE_AND);
6055 }
6056
6057 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
6058
6059 conjunctionable = true;
6060
6061 if ((categoryIds == null) || (categoryIds.length > 0)) {
6062 if (conjunctionable) {
6063 query.append(WHERE_AND);
6064 }
6065
6066 query.append(StringPool.OPEN_PARENTHESIS);
6067
6068 for (int i = 0; i < categoryIds.length; i++) {
6069 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
6070
6071 if ((i + 1) < categoryIds.length) {
6072 query.append(WHERE_OR);
6073 }
6074 }
6075
6076 query.append(StringPool.CLOSE_PARENTHESIS);
6077
6078 conjunctionable = true;
6079 }
6080
6081 if (conjunctionable) {
6082 query.append(WHERE_AND);
6083 }
6084
6085 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
6086
6087 conjunctionable = true;
6088
6089 if (orderByComparator != null) {
6090 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6091 orderByComparator);
6092 }
6093
6094 else {
6095 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6096 }
6097
6098 String sql = query.toString();
6099
6100 Session session = null;
6101
6102 try {
6103 session = openSession();
6104
6105 Query q = session.createQuery(sql);
6106
6107 QueryPos qPos = QueryPos.getInstance(q);
6108
6109 qPos.add(groupId);
6110
6111 if (categoryIds != null) {
6112 qPos.add(categoryIds);
6113 }
6114
6115 qPos.add(status);
6116
6117 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
6118 end);
6119 }
6120 catch (Exception e) {
6121 throw processException(e);
6122 }
6123 finally {
6124 if (list == null) {
6125 FinderCacheUtil.removeResult(finderPath, finderArgs);
6126 }
6127 else {
6128 cacheResult(list);
6129
6130 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6131 }
6132
6133 closeSession(session);
6134 }
6135 }
6136
6137 return list;
6138 }
6139
6140
6149 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6150 int status) throws SystemException {
6151 return filterFindByG_C_S(groupId, categoryId, status,
6152 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6153 }
6154
6155
6170 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6171 int status, int start, int end) throws SystemException {
6172 return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
6173 }
6174
6175
6191 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6192 int status, int start, int end, OrderByComparator orderByComparator)
6193 throws SystemException {
6194 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6195 return findByG_C_S(groupId, categoryId, status, start, end,
6196 orderByComparator);
6197 }
6198
6199 StringBundler query = null;
6200
6201 if (orderByComparator != null) {
6202 query = new StringBundler(5 +
6203 (orderByComparator.getOrderByFields().length * 3));
6204 }
6205 else {
6206 query = new StringBundler(5);
6207 }
6208
6209 if (getDB().isSupportsInlineDistinct()) {
6210 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6211 }
6212 else {
6213 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6214 }
6215
6216 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6217
6218 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6219
6220 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6221
6222 if (!getDB().isSupportsInlineDistinct()) {
6223 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6224 }
6225
6226 if (orderByComparator != null) {
6227 if (getDB().isSupportsInlineDistinct()) {
6228 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6229 orderByComparator);
6230 }
6231 else {
6232 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6233 orderByComparator);
6234 }
6235 }
6236
6237 else {
6238 if (getDB().isSupportsInlineDistinct()) {
6239 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6240 }
6241 else {
6242 query.append(MBThreadModelImpl.ORDER_BY_SQL);
6243 }
6244 }
6245
6246 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6247 MBThread.class.getName(),
6248 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6249
6250 Session session = null;
6251
6252 try {
6253 session = openSession();
6254
6255 SQLQuery q = session.createSQLQuery(sql);
6256
6257 if (getDB().isSupportsInlineDistinct()) {
6258 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6259 }
6260 else {
6261 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6262 }
6263
6264 QueryPos qPos = QueryPos.getInstance(q);
6265
6266 qPos.add(groupId);
6267
6268 qPos.add(categoryId);
6269
6270 qPos.add(status);
6271
6272 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
6273 }
6274 catch (Exception e) {
6275 throw processException(e);
6276 }
6277 finally {
6278 closeSession(session);
6279 }
6280 }
6281
6282
6294 public MBThread[] filterFindByG_C_S_PrevAndNext(long threadId,
6295 long groupId, long categoryId, int status,
6296 OrderByComparator orderByComparator)
6297 throws NoSuchThreadException, SystemException {
6298 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6299 return findByG_C_S_PrevAndNext(threadId, groupId, categoryId,
6300 status, orderByComparator);
6301 }
6302
6303 MBThread mbThread = findByPrimaryKey(threadId);
6304
6305 Session session = null;
6306
6307 try {
6308 session = openSession();
6309
6310 MBThread[] array = new MBThreadImpl[3];
6311
6312 array[0] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
6313 categoryId, status, orderByComparator, true);
6314
6315 array[1] = mbThread;
6316
6317 array[2] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
6318 categoryId, status, orderByComparator, false);
6319
6320 return array;
6321 }
6322 catch (Exception e) {
6323 throw processException(e);
6324 }
6325 finally {
6326 closeSession(session);
6327 }
6328 }
6329
6330 protected MBThread filterGetByG_C_S_PrevAndNext(Session session,
6331 MBThread mbThread, long groupId, long categoryId, int status,
6332 OrderByComparator orderByComparator, boolean previous) {
6333 StringBundler query = null;
6334
6335 if (orderByComparator != null) {
6336 query = new StringBundler(6 +
6337 (orderByComparator.getOrderByFields().length * 6));
6338 }
6339 else {
6340 query = new StringBundler(3);
6341 }
6342
6343 if (getDB().isSupportsInlineDistinct()) {
6344 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6345 }
6346 else {
6347 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6348 }
6349
6350 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6351
6352 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6353
6354 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6355
6356 if (!getDB().isSupportsInlineDistinct()) {
6357 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6358 }
6359
6360 if (orderByComparator != null) {
6361 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6362
6363 if (orderByConditionFields.length > 0) {
6364 query.append(WHERE_AND);
6365 }
6366
6367 for (int i = 0; i < orderByConditionFields.length; i++) {
6368 if (getDB().isSupportsInlineDistinct()) {
6369 query.append(_ORDER_BY_ENTITY_ALIAS);
6370 }
6371 else {
6372 query.append(_ORDER_BY_ENTITY_TABLE);
6373 }
6374
6375 query.append(orderByConditionFields[i]);
6376
6377 if ((i + 1) < orderByConditionFields.length) {
6378 if (orderByComparator.isAscending() ^ previous) {
6379 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6380 }
6381 else {
6382 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6383 }
6384 }
6385 else {
6386 if (orderByComparator.isAscending() ^ previous) {
6387 query.append(WHERE_GREATER_THAN);
6388 }
6389 else {
6390 query.append(WHERE_LESSER_THAN);
6391 }
6392 }
6393 }
6394
6395 query.append(ORDER_BY_CLAUSE);
6396
6397 String[] orderByFields = orderByComparator.getOrderByFields();
6398
6399 for (int i = 0; i < orderByFields.length; i++) {
6400 if (getDB().isSupportsInlineDistinct()) {
6401 query.append(_ORDER_BY_ENTITY_ALIAS);
6402 }
6403 else {
6404 query.append(_ORDER_BY_ENTITY_TABLE);
6405 }
6406
6407 query.append(orderByFields[i]);
6408
6409 if ((i + 1) < orderByFields.length) {
6410 if (orderByComparator.isAscending() ^ previous) {
6411 query.append(ORDER_BY_ASC_HAS_NEXT);
6412 }
6413 else {
6414 query.append(ORDER_BY_DESC_HAS_NEXT);
6415 }
6416 }
6417 else {
6418 if (orderByComparator.isAscending() ^ previous) {
6419 query.append(ORDER_BY_ASC);
6420 }
6421 else {
6422 query.append(ORDER_BY_DESC);
6423 }
6424 }
6425 }
6426 }
6427
6428 else {
6429 if (getDB().isSupportsInlineDistinct()) {
6430 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6431 }
6432 else {
6433 query.append(MBThreadModelImpl.ORDER_BY_SQL);
6434 }
6435 }
6436
6437 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6438 MBThread.class.getName(),
6439 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6440
6441 SQLQuery q = session.createSQLQuery(sql);
6442
6443 q.setFirstResult(0);
6444 q.setMaxResults(2);
6445
6446 if (getDB().isSupportsInlineDistinct()) {
6447 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6448 }
6449 else {
6450 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6451 }
6452
6453 QueryPos qPos = QueryPos.getInstance(q);
6454
6455 qPos.add(groupId);
6456
6457 qPos.add(categoryId);
6458
6459 qPos.add(status);
6460
6461 if (orderByComparator != null) {
6462 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6463
6464 for (Object value : values) {
6465 qPos.add(value);
6466 }
6467 }
6468
6469 List<MBThread> list = q.list();
6470
6471 if (list.size() == 2) {
6472 return list.get(1);
6473 }
6474 else {
6475 return null;
6476 }
6477 }
6478
6479
6488 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6489 int status) throws SystemException {
6490 return filterFindByG_C_S(groupId, categoryIds, status,
6491 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6492 }
6493
6494
6509 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6510 int status, int start, int end) throws SystemException {
6511 return filterFindByG_C_S(groupId, categoryIds, status, start, end, null);
6512 }
6513
6514
6530 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6531 int status, int start, int end, OrderByComparator orderByComparator)
6532 throws SystemException {
6533 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6534 return findByG_C_S(groupId, categoryIds, status, start, end,
6535 orderByComparator);
6536 }
6537
6538 StringBundler query = new StringBundler();
6539
6540 if (getDB().isSupportsInlineDistinct()) {
6541 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6542 }
6543 else {
6544 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6545 }
6546
6547 boolean conjunctionable = false;
6548
6549 if (conjunctionable) {
6550 query.append(WHERE_AND);
6551 }
6552
6553 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
6554
6555 conjunctionable = true;
6556
6557 if ((categoryIds == null) || (categoryIds.length > 0)) {
6558 if (conjunctionable) {
6559 query.append(WHERE_AND);
6560 }
6561
6562 query.append(StringPool.OPEN_PARENTHESIS);
6563
6564 for (int i = 0; i < categoryIds.length; i++) {
6565 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
6566
6567 if ((i + 1) < categoryIds.length) {
6568 query.append(WHERE_OR);
6569 }
6570 }
6571
6572 query.append(StringPool.CLOSE_PARENTHESIS);
6573
6574 conjunctionable = true;
6575 }
6576
6577 if (conjunctionable) {
6578 query.append(WHERE_AND);
6579 }
6580
6581 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
6582
6583 conjunctionable = true;
6584
6585 if (!getDB().isSupportsInlineDistinct()) {
6586 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6587 }
6588
6589 if (orderByComparator != null) {
6590 if (getDB().isSupportsInlineDistinct()) {
6591 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6592 orderByComparator);
6593 }
6594 else {
6595 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6596 orderByComparator);
6597 }
6598 }
6599
6600 else {
6601 if (getDB().isSupportsInlineDistinct()) {
6602 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6603 }
6604 else {
6605 query.append(MBThreadModelImpl.ORDER_BY_SQL);
6606 }
6607 }
6608
6609 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6610 MBThread.class.getName(),
6611 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6612
6613 Session session = null;
6614
6615 try {
6616 session = openSession();
6617
6618 SQLQuery q = session.createSQLQuery(sql);
6619
6620 if (getDB().isSupportsInlineDistinct()) {
6621 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6622 }
6623 else {
6624 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6625 }
6626
6627 QueryPos qPos = QueryPos.getInstance(q);
6628
6629 qPos.add(groupId);
6630
6631 if (categoryIds != null) {
6632 qPos.add(categoryIds);
6633 }
6634
6635 qPos.add(status);
6636
6637 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
6638 }
6639 catch (Exception e) {
6640 throw processException(e);
6641 }
6642 finally {
6643 closeSession(session);
6644 }
6645 }
6646
6647
6656 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6657 int status) throws SystemException {
6658 return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
6659 QueryUtil.ALL_POS, null);
6660 }
6661
6662
6677 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6678 int status, int start, int end) throws SystemException {
6679 return findByG_NotC_S(groupId, categoryId, status, start, end, null);
6680 }
6681
6682
6698 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6699 int status, int start, int end, OrderByComparator orderByComparator)
6700 throws SystemException {
6701 FinderPath finderPath = null;
6702 Object[] finderArgs = null;
6703
6704 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6705 (orderByComparator == null)) {
6706 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S;
6707 finderArgs = new Object[] { groupId, categoryId, status };
6708 }
6709 else {
6710 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S;
6711 finderArgs = new Object[] {
6712 groupId, categoryId, status,
6713
6714 start, end, orderByComparator
6715 };
6716 }
6717
6718 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6719 finderArgs, this);
6720
6721 if (list == null) {
6722 StringBundler query = null;
6723
6724 if (orderByComparator != null) {
6725 query = new StringBundler(5 +
6726 (orderByComparator.getOrderByFields().length * 3));
6727 }
6728 else {
6729 query = new StringBundler(5);
6730 }
6731
6732 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6733
6734 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
6735
6736 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
6737
6738 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
6739
6740 if (orderByComparator != null) {
6741 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6742 orderByComparator);
6743 }
6744
6745 else {
6746 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6747 }
6748
6749 String sql = query.toString();
6750
6751 Session session = null;
6752
6753 try {
6754 session = openSession();
6755
6756 Query q = session.createQuery(sql);
6757
6758 QueryPos qPos = QueryPos.getInstance(q);
6759
6760 qPos.add(groupId);
6761
6762 qPos.add(categoryId);
6763
6764 qPos.add(status);
6765
6766 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
6767 end);
6768 }
6769 catch (Exception e) {
6770 throw processException(e);
6771 }
6772 finally {
6773 if (list == null) {
6774 FinderCacheUtil.removeResult(finderPath, finderArgs);
6775 }
6776 else {
6777 cacheResult(list);
6778
6779 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6780 }
6781
6782 closeSession(session);
6783 }
6784 }
6785
6786 return list;
6787 }
6788
6789
6804 public MBThread findByG_NotC_S_First(long groupId, long categoryId,
6805 int status, OrderByComparator orderByComparator)
6806 throws NoSuchThreadException, SystemException {
6807 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
6808 orderByComparator);
6809
6810 if (list.isEmpty()) {
6811 StringBundler msg = new StringBundler(8);
6812
6813 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6814
6815 msg.append("groupId=");
6816 msg.append(groupId);
6817
6818 msg.append(", categoryId=");
6819 msg.append(categoryId);
6820
6821 msg.append(", status=");
6822 msg.append(status);
6823
6824 msg.append(StringPool.CLOSE_CURLY_BRACE);
6825
6826 throw new NoSuchThreadException(msg.toString());
6827 }
6828 else {
6829 return list.get(0);
6830 }
6831 }
6832
6833
6848 public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
6849 int status, OrderByComparator orderByComparator)
6850 throws NoSuchThreadException, SystemException {
6851 int count = countByG_NotC_S(groupId, categoryId, status);
6852
6853 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
6854 count - 1, count, orderByComparator);
6855
6856 if (list.isEmpty()) {
6857 StringBundler msg = new StringBundler(8);
6858
6859 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6860
6861 msg.append("groupId=");
6862 msg.append(groupId);
6863
6864 msg.append(", categoryId=");
6865 msg.append(categoryId);
6866
6867 msg.append(", status=");
6868 msg.append(status);
6869
6870 msg.append(StringPool.CLOSE_CURLY_BRACE);
6871
6872 throw new NoSuchThreadException(msg.toString());
6873 }
6874 else {
6875 return list.get(0);
6876 }
6877 }
6878
6879
6895 public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
6896 long categoryId, int status, OrderByComparator orderByComparator)
6897 throws NoSuchThreadException, SystemException {
6898 MBThread mbThread = findByPrimaryKey(threadId);
6899
6900 Session session = null;
6901
6902 try {
6903 session = openSession();
6904
6905 MBThread[] array = new MBThreadImpl[3];
6906
6907 array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
6908 categoryId, status, orderByComparator, true);
6909
6910 array[1] = mbThread;
6911
6912 array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
6913 categoryId, status, orderByComparator, false);
6914
6915 return array;
6916 }
6917 catch (Exception e) {
6918 throw processException(e);
6919 }
6920 finally {
6921 closeSession(session);
6922 }
6923 }
6924
6925 protected MBThread getByG_NotC_S_PrevAndNext(Session session,
6926 MBThread mbThread, long groupId, long categoryId, int status,
6927 OrderByComparator orderByComparator, boolean previous) {
6928 StringBundler query = null;
6929
6930 if (orderByComparator != null) {
6931 query = new StringBundler(6 +
6932 (orderByComparator.getOrderByFields().length * 6));
6933 }
6934 else {
6935 query = new StringBundler(3);
6936 }
6937
6938 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6939
6940 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
6941
6942 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
6943
6944 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
6945
6946 if (orderByComparator != null) {
6947 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6948
6949 if (orderByConditionFields.length > 0) {
6950 query.append(WHERE_AND);
6951 }
6952
6953 for (int i = 0; i < orderByConditionFields.length; i++) {
6954 query.append(_ORDER_BY_ENTITY_ALIAS);
6955 query.append(orderByConditionFields[i]);
6956
6957 if ((i + 1) < orderByConditionFields.length) {
6958 if (orderByComparator.isAscending() ^ previous) {
6959 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6960 }
6961 else {
6962 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6963 }
6964 }
6965 else {
6966 if (orderByComparator.isAscending() ^ previous) {
6967 query.append(WHERE_GREATER_THAN);
6968 }
6969 else {
6970 query.append(WHERE_LESSER_THAN);
6971 }
6972 }
6973 }
6974
6975 query.append(ORDER_BY_CLAUSE);
6976
6977 String[] orderByFields = orderByComparator.getOrderByFields();
6978
6979 for (int i = 0; i < orderByFields.length; i++) {
6980 query.append(_ORDER_BY_ENTITY_ALIAS);
6981 query.append(orderByFields[i]);
6982
6983 if ((i + 1) < orderByFields.length) {
6984 if (orderByComparator.isAscending() ^ previous) {
6985 query.append(ORDER_BY_ASC_HAS_NEXT);
6986 }
6987 else {
6988 query.append(ORDER_BY_DESC_HAS_NEXT);
6989 }
6990 }
6991 else {
6992 if (orderByComparator.isAscending() ^ previous) {
6993 query.append(ORDER_BY_ASC);
6994 }
6995 else {
6996 query.append(ORDER_BY_DESC);
6997 }
6998 }
6999 }
7000 }
7001
7002 else {
7003 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7004 }
7005
7006 String sql = query.toString();
7007
7008 Query q = session.createQuery(sql);
7009
7010 q.setFirstResult(0);
7011 q.setMaxResults(2);
7012
7013 QueryPos qPos = QueryPos.getInstance(q);
7014
7015 qPos.add(groupId);
7016
7017 qPos.add(categoryId);
7018
7019 qPos.add(status);
7020
7021 if (orderByComparator != null) {
7022 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7023
7024 for (Object value : values) {
7025 qPos.add(value);
7026 }
7027 }
7028
7029 List<MBThread> list = q.list();
7030
7031 if (list.size() == 2) {
7032 return list.get(1);
7033 }
7034 else {
7035 return null;
7036 }
7037 }
7038
7039
7048 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7049 int status) throws SystemException {
7050 return filterFindByG_NotC_S(groupId, categoryId, status,
7051 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7052 }
7053
7054
7069 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7070 int status, int start, int end) throws SystemException {
7071 return filterFindByG_NotC_S(groupId, categoryId, status, start, end,
7072 null);
7073 }
7074
7075
7091 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7092 int status, int start, int end, OrderByComparator orderByComparator)
7093 throws SystemException {
7094 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7095 return findByG_NotC_S(groupId, categoryId, status, start, end,
7096 orderByComparator);
7097 }
7098
7099 StringBundler query = null;
7100
7101 if (orderByComparator != null) {
7102 query = new StringBundler(5 +
7103 (orderByComparator.getOrderByFields().length * 3));
7104 }
7105 else {
7106 query = new StringBundler(5);
7107 }
7108
7109 if (getDB().isSupportsInlineDistinct()) {
7110 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7111 }
7112 else {
7113 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7114 }
7115
7116 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7117
7118 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7119
7120 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7121
7122 if (!getDB().isSupportsInlineDistinct()) {
7123 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7124 }
7125
7126 if (orderByComparator != null) {
7127 if (getDB().isSupportsInlineDistinct()) {
7128 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7129 orderByComparator);
7130 }
7131 else {
7132 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7133 orderByComparator);
7134 }
7135 }
7136
7137 else {
7138 if (getDB().isSupportsInlineDistinct()) {
7139 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7140 }
7141 else {
7142 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7143 }
7144 }
7145
7146 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7147 MBThread.class.getName(),
7148 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7149
7150 Session session = null;
7151
7152 try {
7153 session = openSession();
7154
7155 SQLQuery q = session.createSQLQuery(sql);
7156
7157 if (getDB().isSupportsInlineDistinct()) {
7158 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7159 }
7160 else {
7161 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7162 }
7163
7164 QueryPos qPos = QueryPos.getInstance(q);
7165
7166 qPos.add(groupId);
7167
7168 qPos.add(categoryId);
7169
7170 qPos.add(status);
7171
7172 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
7173 }
7174 catch (Exception e) {
7175 throw processException(e);
7176 }
7177 finally {
7178 closeSession(session);
7179 }
7180 }
7181
7182
7194 public MBThread[] filterFindByG_NotC_S_PrevAndNext(long threadId,
7195 long groupId, long categoryId, int status,
7196 OrderByComparator orderByComparator)
7197 throws NoSuchThreadException, SystemException {
7198 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7199 return findByG_NotC_S_PrevAndNext(threadId, groupId, categoryId,
7200 status, orderByComparator);
7201 }
7202
7203 MBThread mbThread = findByPrimaryKey(threadId);
7204
7205 Session session = null;
7206
7207 try {
7208 session = openSession();
7209
7210 MBThread[] array = new MBThreadImpl[3];
7211
7212 array[0] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
7213 groupId, categoryId, status, orderByComparator, true);
7214
7215 array[1] = mbThread;
7216
7217 array[2] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
7218 groupId, categoryId, status, orderByComparator, false);
7219
7220 return array;
7221 }
7222 catch (Exception e) {
7223 throw processException(e);
7224 }
7225 finally {
7226 closeSession(session);
7227 }
7228 }
7229
7230 protected MBThread filterGetByG_NotC_S_PrevAndNext(Session session,
7231 MBThread mbThread, long groupId, long categoryId, int status,
7232 OrderByComparator orderByComparator, boolean previous) {
7233 StringBundler query = null;
7234
7235 if (orderByComparator != null) {
7236 query = new StringBundler(6 +
7237 (orderByComparator.getOrderByFields().length * 6));
7238 }
7239 else {
7240 query = new StringBundler(3);
7241 }
7242
7243 if (getDB().isSupportsInlineDistinct()) {
7244 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7245 }
7246 else {
7247 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7248 }
7249
7250 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7251
7252 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7253
7254 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7255
7256 if (!getDB().isSupportsInlineDistinct()) {
7257 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7258 }
7259
7260 if (orderByComparator != null) {
7261 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7262
7263 if (orderByConditionFields.length > 0) {
7264 query.append(WHERE_AND);
7265 }
7266
7267 for (int i = 0; i < orderByConditionFields.length; i++) {
7268 if (getDB().isSupportsInlineDistinct()) {
7269 query.append(_ORDER_BY_ENTITY_ALIAS);
7270 }
7271 else {
7272 query.append(_ORDER_BY_ENTITY_TABLE);
7273 }
7274
7275 query.append(orderByConditionFields[i]);
7276
7277 if ((i + 1) < orderByConditionFields.length) {
7278 if (orderByComparator.isAscending() ^ previous) {
7279 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7280 }
7281 else {
7282 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7283 }
7284 }
7285 else {
7286 if (orderByComparator.isAscending() ^ previous) {
7287 query.append(WHERE_GREATER_THAN);
7288 }
7289 else {
7290 query.append(WHERE_LESSER_THAN);
7291 }
7292 }
7293 }
7294
7295 query.append(ORDER_BY_CLAUSE);
7296
7297 String[] orderByFields = orderByComparator.getOrderByFields();
7298
7299 for (int i = 0; i < orderByFields.length; i++) {
7300 if (getDB().isSupportsInlineDistinct()) {
7301 query.append(_ORDER_BY_ENTITY_ALIAS);
7302 }
7303 else {
7304 query.append(_ORDER_BY_ENTITY_TABLE);
7305 }
7306
7307 query.append(orderByFields[i]);
7308
7309 if ((i + 1) < orderByFields.length) {
7310 if (orderByComparator.isAscending() ^ previous) {
7311 query.append(ORDER_BY_ASC_HAS_NEXT);
7312 }
7313 else {
7314 query.append(ORDER_BY_DESC_HAS_NEXT);
7315 }
7316 }
7317 else {
7318 if (orderByComparator.isAscending() ^ previous) {
7319 query.append(ORDER_BY_ASC);
7320 }
7321 else {
7322 query.append(ORDER_BY_DESC);
7323 }
7324 }
7325 }
7326 }
7327
7328 else {
7329 if (getDB().isSupportsInlineDistinct()) {
7330 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7331 }
7332 else {
7333 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7334 }
7335 }
7336
7337 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7338 MBThread.class.getName(),
7339 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7340
7341 SQLQuery q = session.createSQLQuery(sql);
7342
7343 q.setFirstResult(0);
7344 q.setMaxResults(2);
7345
7346 if (getDB().isSupportsInlineDistinct()) {
7347 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7348 }
7349 else {
7350 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7351 }
7352
7353 QueryPos qPos = QueryPos.getInstance(q);
7354
7355 qPos.add(groupId);
7356
7357 qPos.add(categoryId);
7358
7359 qPos.add(status);
7360
7361 if (orderByComparator != null) {
7362 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7363
7364 for (Object value : values) {
7365 qPos.add(value);
7366 }
7367 }
7368
7369 List<MBThread> list = q.list();
7370
7371 if (list.size() == 2) {
7372 return list.get(1);
7373 }
7374 else {
7375 return null;
7376 }
7377 }
7378
7379
7385 public List<MBThread> findAll() throws SystemException {
7386 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7387 }
7388
7389
7401 public List<MBThread> findAll(int start, int end) throws SystemException {
7402 return findAll(start, end, null);
7403 }
7404
7405
7418 public List<MBThread> findAll(int start, int end,
7419 OrderByComparator orderByComparator) throws SystemException {
7420 FinderPath finderPath = null;
7421 Object[] finderArgs = new Object[] { start, end, orderByComparator };
7422
7423 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7424 (orderByComparator == null)) {
7425 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7426 finderArgs = FINDER_ARGS_EMPTY;
7427 }
7428 else {
7429 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7430 finderArgs = new Object[] { start, end, orderByComparator };
7431 }
7432
7433 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
7434 finderArgs, this);
7435
7436 if (list == null) {
7437 StringBundler query = null;
7438 String sql = null;
7439
7440 if (orderByComparator != null) {
7441 query = new StringBundler(2 +
7442 (orderByComparator.getOrderByFields().length * 3));
7443
7444 query.append(_SQL_SELECT_MBTHREAD);
7445
7446 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7447 orderByComparator);
7448
7449 sql = query.toString();
7450 }
7451 else {
7452 sql = _SQL_SELECT_MBTHREAD.concat(MBThreadModelImpl.ORDER_BY_JPQL);
7453 }
7454
7455 Session session = null;
7456
7457 try {
7458 session = openSession();
7459
7460 Query q = session.createQuery(sql);
7461
7462 if (orderByComparator == null) {
7463 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7464 start, end, false);
7465
7466 Collections.sort(list);
7467 }
7468 else {
7469 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7470 start, end);
7471 }
7472 }
7473 catch (Exception e) {
7474 throw processException(e);
7475 }
7476 finally {
7477 if (list == null) {
7478 FinderCacheUtil.removeResult(finderPath, finderArgs);
7479 }
7480 else {
7481 cacheResult(list);
7482
7483 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7484 }
7485
7486 closeSession(session);
7487 }
7488 }
7489
7490 return list;
7491 }
7492
7493
7499 public void removeByGroupId(long groupId) throws SystemException {
7500 for (MBThread mbThread : findByGroupId(groupId)) {
7501 mbThreadPersistence.remove(mbThread);
7502 }
7503 }
7504
7505
7511 public void removeByRootMessageId(long rootMessageId)
7512 throws NoSuchThreadException, SystemException {
7513 MBThread mbThread = findByRootMessageId(rootMessageId);
7514
7515 mbThreadPersistence.remove(mbThread);
7516 }
7517
7518
7525 public void removeByG_C(long groupId, long categoryId)
7526 throws SystemException {
7527 for (MBThread mbThread : findByG_C(groupId, categoryId)) {
7528 mbThreadPersistence.remove(mbThread);
7529 }
7530 }
7531
7532
7539 public void removeByG_NotC(long groupId, long categoryId)
7540 throws SystemException {
7541 for (MBThread mbThread : findByG_NotC(groupId, categoryId)) {
7542 mbThreadPersistence.remove(mbThread);
7543 }
7544 }
7545
7546
7553 public void removeByG_S(long groupId, int status) throws SystemException {
7554 for (MBThread mbThread : findByG_S(groupId, status)) {
7555 mbThreadPersistence.remove(mbThread);
7556 }
7557 }
7558
7559
7566 public void removeByC_P(long categoryId, double priority)
7567 throws SystemException {
7568 for (MBThread mbThread : findByC_P(categoryId, priority)) {
7569 mbThreadPersistence.remove(mbThread);
7570 }
7571 }
7572
7573
7580 public void removeByL_P(Date lastPostDate, double priority)
7581 throws SystemException {
7582 for (MBThread mbThread : findByL_P(lastPostDate, priority)) {
7583 mbThreadPersistence.remove(mbThread);
7584 }
7585 }
7586
7587
7595 public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
7596 throws SystemException {
7597 for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate)) {
7598 mbThreadPersistence.remove(mbThread);
7599 }
7600 }
7601
7602
7610 public void removeByG_C_S(long groupId, long categoryId, int status)
7611 throws SystemException {
7612 for (MBThread mbThread : findByG_C_S(groupId, categoryId, status)) {
7613 mbThreadPersistence.remove(mbThread);
7614 }
7615 }
7616
7617
7625 public void removeByG_NotC_S(long groupId, long categoryId, int status)
7626 throws SystemException {
7627 for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status)) {
7628 mbThreadPersistence.remove(mbThread);
7629 }
7630 }
7631
7632
7637 public void removeAll() throws SystemException {
7638 for (MBThread mbThread : findAll()) {
7639 mbThreadPersistence.remove(mbThread);
7640 }
7641 }
7642
7643
7650 public int countByGroupId(long groupId) throws SystemException {
7651 Object[] finderArgs = new Object[] { groupId };
7652
7653 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
7654 finderArgs, this);
7655
7656 if (count == null) {
7657 StringBundler query = new StringBundler(2);
7658
7659 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7660
7661 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
7662
7663 String sql = query.toString();
7664
7665 Session session = null;
7666
7667 try {
7668 session = openSession();
7669
7670 Query q = session.createQuery(sql);
7671
7672 QueryPos qPos = QueryPos.getInstance(q);
7673
7674 qPos.add(groupId);
7675
7676 count = (Long)q.uniqueResult();
7677 }
7678 catch (Exception e) {
7679 throw processException(e);
7680 }
7681 finally {
7682 if (count == null) {
7683 count = Long.valueOf(0);
7684 }
7685
7686 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
7687 finderArgs, count);
7688
7689 closeSession(session);
7690 }
7691 }
7692
7693 return count.intValue();
7694 }
7695
7696
7703 public int filterCountByGroupId(long groupId) throws SystemException {
7704 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7705 return countByGroupId(groupId);
7706 }
7707
7708 StringBundler query = new StringBundler(2);
7709
7710 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7711
7712 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
7713
7714 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7715 MBThread.class.getName(),
7716 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7717
7718 Session session = null;
7719
7720 try {
7721 session = openSession();
7722
7723 SQLQuery q = session.createSQLQuery(sql);
7724
7725 q.addScalar(COUNT_COLUMN_NAME,
7726 com.liferay.portal.kernel.dao.orm.Type.LONG);
7727
7728 QueryPos qPos = QueryPos.getInstance(q);
7729
7730 qPos.add(groupId);
7731
7732 Long count = (Long)q.uniqueResult();
7733
7734 return count.intValue();
7735 }
7736 catch (Exception e) {
7737 throw processException(e);
7738 }
7739 finally {
7740 closeSession(session);
7741 }
7742 }
7743
7744
7751 public int countByRootMessageId(long rootMessageId)
7752 throws SystemException {
7753 Object[] finderArgs = new Object[] { rootMessageId };
7754
7755 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
7756 finderArgs, this);
7757
7758 if (count == null) {
7759 StringBundler query = new StringBundler(2);
7760
7761 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7762
7763 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
7764
7765 String sql = query.toString();
7766
7767 Session session = null;
7768
7769 try {
7770 session = openSession();
7771
7772 Query q = session.createQuery(sql);
7773
7774 QueryPos qPos = QueryPos.getInstance(q);
7775
7776 qPos.add(rootMessageId);
7777
7778 count = (Long)q.uniqueResult();
7779 }
7780 catch (Exception e) {
7781 throw processException(e);
7782 }
7783 finally {
7784 if (count == null) {
7785 count = Long.valueOf(0);
7786 }
7787
7788 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
7789 finderArgs, count);
7790
7791 closeSession(session);
7792 }
7793 }
7794
7795 return count.intValue();
7796 }
7797
7798
7806 public int countByG_C(long groupId, long categoryId)
7807 throws SystemException {
7808 Object[] finderArgs = new Object[] { groupId, categoryId };
7809
7810 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
7811 finderArgs, this);
7812
7813 if (count == null) {
7814 StringBundler query = new StringBundler(3);
7815
7816 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7817
7818 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
7819
7820 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
7821
7822 String sql = query.toString();
7823
7824 Session session = null;
7825
7826 try {
7827 session = openSession();
7828
7829 Query q = session.createQuery(sql);
7830
7831 QueryPos qPos = QueryPos.getInstance(q);
7832
7833 qPos.add(groupId);
7834
7835 qPos.add(categoryId);
7836
7837 count = (Long)q.uniqueResult();
7838 }
7839 catch (Exception e) {
7840 throw processException(e);
7841 }
7842 finally {
7843 if (count == null) {
7844 count = Long.valueOf(0);
7845 }
7846
7847 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
7848 count);
7849
7850 closeSession(session);
7851 }
7852 }
7853
7854 return count.intValue();
7855 }
7856
7857
7865 public int countByG_C(long groupId, long[] categoryIds)
7866 throws SystemException {
7867 Object[] finderArgs = new Object[] {
7868 groupId, StringUtil.merge(categoryIds)
7869 };
7870
7871 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
7872 finderArgs, this);
7873
7874 if (count == null) {
7875 StringBundler query = new StringBundler();
7876
7877 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7878
7879 boolean conjunctionable = false;
7880
7881 if (conjunctionable) {
7882 query.append(WHERE_AND);
7883 }
7884
7885 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
7886
7887 conjunctionable = true;
7888
7889 if ((categoryIds == null) || (categoryIds.length > 0)) {
7890 if (conjunctionable) {
7891 query.append(WHERE_AND);
7892 }
7893
7894 query.append(StringPool.OPEN_PARENTHESIS);
7895
7896 for (int i = 0; i < categoryIds.length; i++) {
7897 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
7898
7899 if ((i + 1) < categoryIds.length) {
7900 query.append(WHERE_OR);
7901 }
7902 }
7903
7904 query.append(StringPool.CLOSE_PARENTHESIS);
7905
7906 conjunctionable = true;
7907 }
7908
7909 String sql = query.toString();
7910
7911 Session session = null;
7912
7913 try {
7914 session = openSession();
7915
7916 Query q = session.createQuery(sql);
7917
7918 QueryPos qPos = QueryPos.getInstance(q);
7919
7920 qPos.add(groupId);
7921
7922 if (categoryIds != null) {
7923 qPos.add(categoryIds);
7924 }
7925
7926 count = (Long)q.uniqueResult();
7927 }
7928 catch (Exception e) {
7929 throw processException(e);
7930 }
7931 finally {
7932 if (count == null) {
7933 count = Long.valueOf(0);
7934 }
7935
7936 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
7937 count);
7938
7939 closeSession(session);
7940 }
7941 }
7942
7943 return count.intValue();
7944 }
7945
7946
7954 public int filterCountByG_C(long groupId, long categoryId)
7955 throws SystemException {
7956 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7957 return countByG_C(groupId, categoryId);
7958 }
7959
7960 StringBundler query = new StringBundler(3);
7961
7962 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7963
7964 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
7965
7966 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
7967
7968 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7969 MBThread.class.getName(),
7970 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7971
7972 Session session = null;
7973
7974 try {
7975 session = openSession();
7976
7977 SQLQuery q = session.createSQLQuery(sql);
7978
7979 q.addScalar(COUNT_COLUMN_NAME,
7980 com.liferay.portal.kernel.dao.orm.Type.LONG);
7981
7982 QueryPos qPos = QueryPos.getInstance(q);
7983
7984 qPos.add(groupId);
7985
7986 qPos.add(categoryId);
7987
7988 Long count = (Long)q.uniqueResult();
7989
7990 return count.intValue();
7991 }
7992 catch (Exception e) {
7993 throw processException(e);
7994 }
7995 finally {
7996 closeSession(session);
7997 }
7998 }
7999
8000
8008 public int filterCountByG_C(long groupId, long[] categoryIds)
8009 throws SystemException {
8010 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8011 return countByG_C(groupId, categoryIds);
8012 }
8013
8014 StringBundler query = new StringBundler();
8015
8016 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8017
8018 boolean conjunctionable = false;
8019
8020 if (conjunctionable) {
8021 query.append(WHERE_AND);
8022 }
8023
8024 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
8025
8026 conjunctionable = true;
8027
8028 if ((categoryIds == null) || (categoryIds.length > 0)) {
8029 if (conjunctionable) {
8030 query.append(WHERE_AND);
8031 }
8032
8033 query.append(StringPool.OPEN_PARENTHESIS);
8034
8035 for (int i = 0; i < categoryIds.length; i++) {
8036 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
8037
8038 if ((i + 1) < categoryIds.length) {
8039 query.append(WHERE_OR);
8040 }
8041 }
8042
8043 query.append(StringPool.CLOSE_PARENTHESIS);
8044
8045 conjunctionable = true;
8046 }
8047
8048 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8049 MBThread.class.getName(),
8050 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8051
8052 Session session = null;
8053
8054 try {
8055 session = openSession();
8056
8057 SQLQuery q = session.createSQLQuery(sql);
8058
8059 q.addScalar(COUNT_COLUMN_NAME,
8060 com.liferay.portal.kernel.dao.orm.Type.LONG);
8061
8062 QueryPos qPos = QueryPos.getInstance(q);
8063
8064 qPos.add(groupId);
8065
8066 if (categoryIds != null) {
8067 qPos.add(categoryIds);
8068 }
8069
8070 Long count = (Long)q.uniqueResult();
8071
8072 return count.intValue();
8073 }
8074 catch (Exception e) {
8075 throw processException(e);
8076 }
8077 finally {
8078 closeSession(session);
8079 }
8080 }
8081
8082
8090 public int countByG_NotC(long groupId, long categoryId)
8091 throws SystemException {
8092 Object[] finderArgs = new Object[] { groupId, categoryId };
8093
8094 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTC,
8095 finderArgs, this);
8096
8097 if (count == null) {
8098 StringBundler query = new StringBundler(3);
8099
8100 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8101
8102 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
8103
8104 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
8105
8106 String sql = query.toString();
8107
8108 Session session = null;
8109
8110 try {
8111 session = openSession();
8112
8113 Query q = session.createQuery(sql);
8114
8115 QueryPos qPos = QueryPos.getInstance(q);
8116
8117 qPos.add(groupId);
8118
8119 qPos.add(categoryId);
8120
8121 count = (Long)q.uniqueResult();
8122 }
8123 catch (Exception e) {
8124 throw processException(e);
8125 }
8126 finally {
8127 if (count == null) {
8128 count = Long.valueOf(0);
8129 }
8130
8131 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTC,
8132 finderArgs, count);
8133
8134 closeSession(session);
8135 }
8136 }
8137
8138 return count.intValue();
8139 }
8140
8141
8149 public int filterCountByG_NotC(long groupId, long categoryId)
8150 throws SystemException {
8151 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8152 return countByG_NotC(groupId, categoryId);
8153 }
8154
8155 StringBundler query = new StringBundler(3);
8156
8157 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8158
8159 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
8160
8161 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
8162
8163 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8164 MBThread.class.getName(),
8165 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8166
8167 Session session = null;
8168
8169 try {
8170 session = openSession();
8171
8172 SQLQuery q = session.createSQLQuery(sql);
8173
8174 q.addScalar(COUNT_COLUMN_NAME,
8175 com.liferay.portal.kernel.dao.orm.Type.LONG);
8176
8177 QueryPos qPos = QueryPos.getInstance(q);
8178
8179 qPos.add(groupId);
8180
8181 qPos.add(categoryId);
8182
8183 Long count = (Long)q.uniqueResult();
8184
8185 return count.intValue();
8186 }
8187 catch (Exception e) {
8188 throw processException(e);
8189 }
8190 finally {
8191 closeSession(session);
8192 }
8193 }
8194
8195
8203 public int countByG_S(long groupId, int status) throws SystemException {
8204 Object[] finderArgs = new Object[] { groupId, status };
8205
8206 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
8207 finderArgs, this);
8208
8209 if (count == null) {
8210 StringBundler query = new StringBundler(3);
8211
8212 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8213
8214 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
8215
8216 query.append(_FINDER_COLUMN_G_S_STATUS_2);
8217
8218 String sql = query.toString();
8219
8220 Session session = null;
8221
8222 try {
8223 session = openSession();
8224
8225 Query q = session.createQuery(sql);
8226
8227 QueryPos qPos = QueryPos.getInstance(q);
8228
8229 qPos.add(groupId);
8230
8231 qPos.add(status);
8232
8233 count = (Long)q.uniqueResult();
8234 }
8235 catch (Exception e) {
8236 throw processException(e);
8237 }
8238 finally {
8239 if (count == null) {
8240 count = Long.valueOf(0);
8241 }
8242
8243 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
8244 count);
8245
8246 closeSession(session);
8247 }
8248 }
8249
8250 return count.intValue();
8251 }
8252
8253
8261 public int filterCountByG_S(long groupId, int status)
8262 throws SystemException {
8263 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8264 return countByG_S(groupId, status);
8265 }
8266
8267 StringBundler query = new StringBundler(3);
8268
8269 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8270
8271 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
8272
8273 query.append(_FINDER_COLUMN_G_S_STATUS_2);
8274
8275 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8276 MBThread.class.getName(),
8277 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8278
8279 Session session = null;
8280
8281 try {
8282 session = openSession();
8283
8284 SQLQuery q = session.createSQLQuery(sql);
8285
8286 q.addScalar(COUNT_COLUMN_NAME,
8287 com.liferay.portal.kernel.dao.orm.Type.LONG);
8288
8289 QueryPos qPos = QueryPos.getInstance(q);
8290
8291 qPos.add(groupId);
8292
8293 qPos.add(status);
8294
8295 Long count = (Long)q.uniqueResult();
8296
8297 return count.intValue();
8298 }
8299 catch (Exception e) {
8300 throw processException(e);
8301 }
8302 finally {
8303 closeSession(session);
8304 }
8305 }
8306
8307
8315 public int countByC_P(long categoryId, double priority)
8316 throws SystemException {
8317 Object[] finderArgs = new Object[] { categoryId, priority };
8318
8319 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
8320 finderArgs, this);
8321
8322 if (count == null) {
8323 StringBundler query = new StringBundler(3);
8324
8325 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8326
8327 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
8328
8329 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
8330
8331 String sql = query.toString();
8332
8333 Session session = null;
8334
8335 try {
8336 session = openSession();
8337
8338 Query q = session.createQuery(sql);
8339
8340 QueryPos qPos = QueryPos.getInstance(q);
8341
8342 qPos.add(categoryId);
8343
8344 qPos.add(priority);
8345
8346 count = (Long)q.uniqueResult();
8347 }
8348 catch (Exception e) {
8349 throw processException(e);
8350 }
8351 finally {
8352 if (count == null) {
8353 count = Long.valueOf(0);
8354 }
8355
8356 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
8357 count);
8358
8359 closeSession(session);
8360 }
8361 }
8362
8363 return count.intValue();
8364 }
8365
8366
8374 public int countByL_P(Date lastPostDate, double priority)
8375 throws SystemException {
8376 Object[] finderArgs = new Object[] { lastPostDate, priority };
8377
8378 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_L_P,
8379 finderArgs, this);
8380
8381 if (count == null) {
8382 StringBundler query = new StringBundler(3);
8383
8384 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8385
8386 if (lastPostDate == null) {
8387 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
8388 }
8389 else {
8390 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
8391 }
8392
8393 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
8394
8395 String sql = query.toString();
8396
8397 Session session = null;
8398
8399 try {
8400 session = openSession();
8401
8402 Query q = session.createQuery(sql);
8403
8404 QueryPos qPos = QueryPos.getInstance(q);
8405
8406 if (lastPostDate != null) {
8407 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8408 }
8409
8410 qPos.add(priority);
8411
8412 count = (Long)q.uniqueResult();
8413 }
8414 catch (Exception e) {
8415 throw processException(e);
8416 }
8417 finally {
8418 if (count == null) {
8419 count = Long.valueOf(0);
8420 }
8421
8422 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_L_P, finderArgs,
8423 count);
8424
8425 closeSession(session);
8426 }
8427 }
8428
8429 return count.intValue();
8430 }
8431
8432
8441 public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
8442 throws SystemException {
8443 Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
8444
8445 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_L,
8446 finderArgs, this);
8447
8448 if (count == null) {
8449 StringBundler query = new StringBundler(4);
8450
8451 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8452
8453 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
8454
8455 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
8456
8457 if (lastPostDate == null) {
8458 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
8459 }
8460 else {
8461 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
8462 }
8463
8464 String sql = query.toString();
8465
8466 Session session = null;
8467
8468 try {
8469 session = openSession();
8470
8471 Query q = session.createQuery(sql);
8472
8473 QueryPos qPos = QueryPos.getInstance(q);
8474
8475 qPos.add(groupId);
8476
8477 qPos.add(categoryId);
8478
8479 if (lastPostDate != null) {
8480 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8481 }
8482
8483 count = (Long)q.uniqueResult();
8484 }
8485 catch (Exception e) {
8486 throw processException(e);
8487 }
8488 finally {
8489 if (count == null) {
8490 count = Long.valueOf(0);
8491 }
8492
8493 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_L,
8494 finderArgs, count);
8495
8496 closeSession(session);
8497 }
8498 }
8499
8500 return count.intValue();
8501 }
8502
8503
8512 public int filterCountByG_C_L(long groupId, long categoryId,
8513 Date lastPostDate) throws SystemException {
8514 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8515 return countByG_C_L(groupId, categoryId, lastPostDate);
8516 }
8517
8518 StringBundler query = new StringBundler(4);
8519
8520 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8521
8522 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
8523
8524 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
8525
8526 if (lastPostDate == null) {
8527 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
8528 }
8529 else {
8530 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
8531 }
8532
8533 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8534 MBThread.class.getName(),
8535 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8536
8537 Session session = null;
8538
8539 try {
8540 session = openSession();
8541
8542 SQLQuery q = session.createSQLQuery(sql);
8543
8544 q.addScalar(COUNT_COLUMN_NAME,
8545 com.liferay.portal.kernel.dao.orm.Type.LONG);
8546
8547 QueryPos qPos = QueryPos.getInstance(q);
8548
8549 qPos.add(groupId);
8550
8551 qPos.add(categoryId);
8552
8553 if (lastPostDate != null) {
8554 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8555 }
8556
8557 Long count = (Long)q.uniqueResult();
8558
8559 return count.intValue();
8560 }
8561 catch (Exception e) {
8562 throw processException(e);
8563 }
8564 finally {
8565 closeSession(session);
8566 }
8567 }
8568
8569
8578 public int countByG_C_S(long groupId, long categoryId, int status)
8579 throws SystemException {
8580 Object[] finderArgs = new Object[] { groupId, categoryId, status };
8581
8582 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
8583 finderArgs, this);
8584
8585 if (count == null) {
8586 StringBundler query = new StringBundler(4);
8587
8588 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8589
8590 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8591
8592 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8593
8594 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8595
8596 String sql = query.toString();
8597
8598 Session session = null;
8599
8600 try {
8601 session = openSession();
8602
8603 Query q = session.createQuery(sql);
8604
8605 QueryPos qPos = QueryPos.getInstance(q);
8606
8607 qPos.add(groupId);
8608
8609 qPos.add(categoryId);
8610
8611 qPos.add(status);
8612
8613 count = (Long)q.uniqueResult();
8614 }
8615 catch (Exception e) {
8616 throw processException(e);
8617 }
8618 finally {
8619 if (count == null) {
8620 count = Long.valueOf(0);
8621 }
8622
8623 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
8624 finderArgs, count);
8625
8626 closeSession(session);
8627 }
8628 }
8629
8630 return count.intValue();
8631 }
8632
8633
8642 public int countByG_C_S(long groupId, long[] categoryIds, int status)
8643 throws SystemException {
8644 Object[] finderArgs = new Object[] {
8645 groupId, StringUtil.merge(categoryIds), status
8646 };
8647
8648 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
8649 finderArgs, this);
8650
8651 if (count == null) {
8652 StringBundler query = new StringBundler();
8653
8654 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8655
8656 boolean conjunctionable = false;
8657
8658 if (conjunctionable) {
8659 query.append(WHERE_AND);
8660 }
8661
8662 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
8663
8664 conjunctionable = true;
8665
8666 if ((categoryIds == null) || (categoryIds.length > 0)) {
8667 if (conjunctionable) {
8668 query.append(WHERE_AND);
8669 }
8670
8671 query.append(StringPool.OPEN_PARENTHESIS);
8672
8673 for (int i = 0; i < categoryIds.length; i++) {
8674 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
8675
8676 if ((i + 1) < categoryIds.length) {
8677 query.append(WHERE_OR);
8678 }
8679 }
8680
8681 query.append(StringPool.CLOSE_PARENTHESIS);
8682
8683 conjunctionable = true;
8684 }
8685
8686 if (conjunctionable) {
8687 query.append(WHERE_AND);
8688 }
8689
8690 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
8691
8692 conjunctionable = true;
8693
8694 String sql = query.toString();
8695
8696 Session session = null;
8697
8698 try {
8699 session = openSession();
8700
8701 Query q = session.createQuery(sql);
8702
8703 QueryPos qPos = QueryPos.getInstance(q);
8704
8705 qPos.add(groupId);
8706
8707 if (categoryIds != null) {
8708 qPos.add(categoryIds);
8709 }
8710
8711 qPos.add(status);
8712
8713 count = (Long)q.uniqueResult();
8714 }
8715 catch (Exception e) {
8716 throw processException(e);
8717 }
8718 finally {
8719 if (count == null) {
8720 count = Long.valueOf(0);
8721 }
8722
8723 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
8724 finderArgs, count);
8725
8726 closeSession(session);
8727 }
8728 }
8729
8730 return count.intValue();
8731 }
8732
8733
8742 public int filterCountByG_C_S(long groupId, long categoryId, int status)
8743 throws SystemException {
8744 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8745 return countByG_C_S(groupId, categoryId, status);
8746 }
8747
8748 StringBundler query = new StringBundler(4);
8749
8750 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8751
8752 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8753
8754 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8755
8756 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8757
8758 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8759 MBThread.class.getName(),
8760 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8761
8762 Session session = null;
8763
8764 try {
8765 session = openSession();
8766
8767 SQLQuery q = session.createSQLQuery(sql);
8768
8769 q.addScalar(COUNT_COLUMN_NAME,
8770 com.liferay.portal.kernel.dao.orm.Type.LONG);
8771
8772 QueryPos qPos = QueryPos.getInstance(q);
8773
8774 qPos.add(groupId);
8775
8776 qPos.add(categoryId);
8777
8778 qPos.add(status);
8779
8780 Long count = (Long)q.uniqueResult();
8781
8782 return count.intValue();
8783 }
8784 catch (Exception e) {
8785 throw processException(e);
8786 }
8787 finally {
8788 closeSession(session);
8789 }
8790 }
8791
8792
8801 public int filterCountByG_C_S(long groupId, long[] categoryIds, int status)
8802 throws SystemException {
8803 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8804 return countByG_C_S(groupId, categoryIds, status);
8805 }
8806
8807 StringBundler query = new StringBundler();
8808
8809 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8810
8811 boolean conjunctionable = false;
8812
8813 if (conjunctionable) {
8814 query.append(WHERE_AND);
8815 }
8816
8817 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
8818
8819 conjunctionable = true;
8820
8821 if ((categoryIds == null) || (categoryIds.length > 0)) {
8822 if (conjunctionable) {
8823 query.append(WHERE_AND);
8824 }
8825
8826 query.append(StringPool.OPEN_PARENTHESIS);
8827
8828 for (int i = 0; i < categoryIds.length; i++) {
8829 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
8830
8831 if ((i + 1) < categoryIds.length) {
8832 query.append(WHERE_OR);
8833 }
8834 }
8835
8836 query.append(StringPool.CLOSE_PARENTHESIS);
8837
8838 conjunctionable = true;
8839 }
8840
8841 if (conjunctionable) {
8842 query.append(WHERE_AND);
8843 }
8844
8845 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
8846
8847 conjunctionable = true;
8848
8849 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8850 MBThread.class.getName(),
8851 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8852
8853 Session session = null;
8854
8855 try {
8856 session = openSession();
8857
8858 SQLQuery q = session.createSQLQuery(sql);
8859
8860 q.addScalar(COUNT_COLUMN_NAME,
8861 com.liferay.portal.kernel.dao.orm.Type.LONG);
8862
8863 QueryPos qPos = QueryPos.getInstance(q);
8864
8865 qPos.add(groupId);
8866
8867 if (categoryIds != null) {
8868 qPos.add(categoryIds);
8869 }
8870
8871 qPos.add(status);
8872
8873 Long count = (Long)q.uniqueResult();
8874
8875 return count.intValue();
8876 }
8877 catch (Exception e) {
8878 throw processException(e);
8879 }
8880 finally {
8881 closeSession(session);
8882 }
8883 }
8884
8885
8894 public int countByG_NotC_S(long groupId, long categoryId, int status)
8895 throws SystemException {
8896 Object[] finderArgs = new Object[] { groupId, categoryId, status };
8897
8898 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTC_S,
8899 finderArgs, this);
8900
8901 if (count == null) {
8902 StringBundler query = new StringBundler(4);
8903
8904 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8905
8906 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
8907
8908 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
8909
8910 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
8911
8912 String sql = query.toString();
8913
8914 Session session = null;
8915
8916 try {
8917 session = openSession();
8918
8919 Query q = session.createQuery(sql);
8920
8921 QueryPos qPos = QueryPos.getInstance(q);
8922
8923 qPos.add(groupId);
8924
8925 qPos.add(categoryId);
8926
8927 qPos.add(status);
8928
8929 count = (Long)q.uniqueResult();
8930 }
8931 catch (Exception e) {
8932 throw processException(e);
8933 }
8934 finally {
8935 if (count == null) {
8936 count = Long.valueOf(0);
8937 }
8938
8939 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTC_S,
8940 finderArgs, count);
8941
8942 closeSession(session);
8943 }
8944 }
8945
8946 return count.intValue();
8947 }
8948
8949
8958 public int filterCountByG_NotC_S(long groupId, long categoryId, int status)
8959 throws SystemException {
8960 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8961 return countByG_NotC_S(groupId, categoryId, status);
8962 }
8963
8964 StringBundler query = new StringBundler(4);
8965
8966 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8967
8968 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
8969
8970 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
8971
8972 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
8973
8974 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8975 MBThread.class.getName(),
8976 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8977
8978 Session session = null;
8979
8980 try {
8981 session = openSession();
8982
8983 SQLQuery q = session.createSQLQuery(sql);
8984
8985 q.addScalar(COUNT_COLUMN_NAME,
8986 com.liferay.portal.kernel.dao.orm.Type.LONG);
8987
8988 QueryPos qPos = QueryPos.getInstance(q);
8989
8990 qPos.add(groupId);
8991
8992 qPos.add(categoryId);
8993
8994 qPos.add(status);
8995
8996 Long count = (Long)q.uniqueResult();
8997
8998 return count.intValue();
8999 }
9000 catch (Exception e) {
9001 throw processException(e);
9002 }
9003 finally {
9004 closeSession(session);
9005 }
9006 }
9007
9008
9014 public int countAll() throws SystemException {
9015 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9016 FINDER_ARGS_EMPTY, this);
9017
9018 if (count == null) {
9019 Session session = null;
9020
9021 try {
9022 session = openSession();
9023
9024 Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
9025
9026 count = (Long)q.uniqueResult();
9027 }
9028 catch (Exception e) {
9029 throw processException(e);
9030 }
9031 finally {
9032 if (count == null) {
9033 count = Long.valueOf(0);
9034 }
9035
9036 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
9037 FINDER_ARGS_EMPTY, count);
9038
9039 closeSession(session);
9040 }
9041 }
9042
9043 return count.intValue();
9044 }
9045
9046
9049 public void afterPropertiesSet() {
9050 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9051 com.liferay.portal.util.PropsUtil.get(
9052 "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
9053
9054 if (listenerClassNames.length > 0) {
9055 try {
9056 List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
9057
9058 for (String listenerClassName : listenerClassNames) {
9059 listenersList.add((ModelListener<MBThread>)InstanceFactory.newInstance(
9060 listenerClassName));
9061 }
9062
9063 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9064 }
9065 catch (Exception e) {
9066 _log.error(e);
9067 }
9068 }
9069 }
9070
9071 public void destroy() {
9072 EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
9073 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9074 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9075 }
9076
9077 @BeanReference(type = MBBanPersistence.class)
9078 protected MBBanPersistence mbBanPersistence;
9079 @BeanReference(type = MBCategoryPersistence.class)
9080 protected MBCategoryPersistence mbCategoryPersistence;
9081 @BeanReference(type = MBDiscussionPersistence.class)
9082 protected MBDiscussionPersistence mbDiscussionPersistence;
9083 @BeanReference(type = MBMailingListPersistence.class)
9084 protected MBMailingListPersistence mbMailingListPersistence;
9085 @BeanReference(type = MBMessagePersistence.class)
9086 protected MBMessagePersistence mbMessagePersistence;
9087 @BeanReference(type = MBStatsUserPersistence.class)
9088 protected MBStatsUserPersistence mbStatsUserPersistence;
9089 @BeanReference(type = MBThreadPersistence.class)
9090 protected MBThreadPersistence mbThreadPersistence;
9091 @BeanReference(type = MBThreadFlagPersistence.class)
9092 protected MBThreadFlagPersistence mbThreadFlagPersistence;
9093 @BeanReference(type = LockPersistence.class)
9094 protected LockPersistence lockPersistence;
9095 @BeanReference(type = ResourcePersistence.class)
9096 protected ResourcePersistence resourcePersistence;
9097 @BeanReference(type = UserPersistence.class)
9098 protected UserPersistence userPersistence;
9099 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
9100 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
9101 @BeanReference(type = AssetEntryPersistence.class)
9102 protected AssetEntryPersistence assetEntryPersistence;
9103 @BeanReference(type = RatingsStatsPersistence.class)
9104 protected RatingsStatsPersistence ratingsStatsPersistence;
9105 @BeanReference(type = SocialActivityPersistence.class)
9106 protected SocialActivityPersistence socialActivityPersistence;
9107 private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
9108 private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
9109 private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
9110 private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
9111 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ?";
9112 private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
9113 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
9114 private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
9115 _removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
9116 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
9117 private static final String _FINDER_COLUMN_G_C_CATEGORYID_5 = "(" +
9118 _removeConjunction(_FINDER_COLUMN_G_C_CATEGORYID_2) + ")";
9119 private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
9120 private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
9121 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9122 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
9123 private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9124 private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
9125 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL AND ";
9126 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_2 = "mbThread.lastPostDate = ? AND ";
9127 private static final String _FINDER_COLUMN_L_P_PRIORITY_2 = "mbThread.priority = ?";
9128 private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
9129 private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9130 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
9131 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
9132 private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9133 private static final String _FINDER_COLUMN_G_C_S_GROUPID_5 = "(" +
9134 _removeConjunction(_FINDER_COLUMN_G_C_S_GROUPID_2) + ")";
9135 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9136 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_5 = "(" +
9137 _removeConjunction(_FINDER_COLUMN_G_C_S_CATEGORYID_2) + ")";
9138 private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
9139 private static final String _FINDER_COLUMN_G_C_S_STATUS_5 = "(" +
9140 _removeConjunction(_FINDER_COLUMN_G_C_S_STATUS_2) + ")";
9141 private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9142 private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
9143 private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
9144
9145 private static String _removeConjunction(String sql) {
9146 int pos = sql.indexOf(" AND ");
9147
9148 if (pos != -1) {
9149 sql = sql.substring(0, pos);
9150 }
9151
9152 return sql;
9153 }
9154
9155 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbThread.threadId";
9156 private static final String _FILTER_SQL_SELECT_MBTHREAD_WHERE = "SELECT DISTINCT {mbThread.*} FROM MBThread mbThread WHERE ";
9157 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1 =
9158 "SELECT {MBThread.*} FROM (SELECT DISTINCT mbThread.threadId FROM MBThread mbThread WHERE ";
9159 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2 =
9160 ") TEMP_TABLE INNER JOIN MBThread ON TEMP_TABLE.threadId = MBThread.threadId";
9161 private static final String _FILTER_SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(DISTINCT mbThread.threadId) AS COUNT_VALUE FROM MBThread mbThread WHERE ";
9162 private static final String _FILTER_ENTITY_ALIAS = "mbThread";
9163 private static final String _FILTER_ENTITY_TABLE = "MBThread";
9164 private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
9165 private static final String _ORDER_BY_ENTITY_TABLE = "MBThread.";
9166 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
9167 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
9168 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9169 private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
9170 private static MBThread _nullMBThread = new MBThreadImpl() {
9171 @Override
9172 public Object clone() {
9173 return this;
9174 }
9175
9176 @Override
9177 public CacheModel<MBThread> toCacheModel() {
9178 return _nullMBThreadCacheModel;
9179 }
9180 };
9181
9182 private static CacheModel<MBThread> _nullMBThreadCacheModel = new CacheModel<MBThread>() {
9183 public MBThread toEntityModel() {
9184 return _nullMBThread;
9185 }
9186 };
9187 }