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