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.ArrayUtil;
032 import com.liferay.portal.kernel.util.CalendarUtil;
033 import com.liferay.portal.kernel.util.GetterUtil;
034 import com.liferay.portal.kernel.util.InstanceFactory;
035 import com.liferay.portal.kernel.util.OrderByComparator;
036 import com.liferay.portal.kernel.util.StringBundler;
037 import com.liferay.portal.kernel.util.StringPool;
038 import com.liferay.portal.kernel.util.StringUtil;
039 import com.liferay.portal.kernel.util.Validator;
040 import com.liferay.portal.model.CacheModel;
041 import com.liferay.portal.model.ModelListener;
042 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043 import com.liferay.portal.service.persistence.BatchSessionUtil;
044 import com.liferay.portal.service.persistence.LockPersistence;
045 import com.liferay.portal.service.persistence.ResourcePersistence;
046 import com.liferay.portal.service.persistence.UserPersistence;
047 import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
048 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049
050 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
051 import com.liferay.portlet.messageboards.NoSuchThreadException;
052 import com.liferay.portlet.messageboards.model.MBThread;
053 import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
054 import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
055 import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
056 import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
057
058 import java.io.Serializable;
059
060 import java.util.ArrayList;
061 import java.util.Collections;
062 import java.util.Date;
063 import java.util.List;
064
065
077 public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
078 implements MBThreadPersistence {
079
084 public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
085 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List1";
087 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
088 ".List2";
089 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
090 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
091 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
092 new String[] {
093 Long.class.getName(),
094
095 "java.lang.Integer", "java.lang.Integer",
096 "com.liferay.portal.kernel.util.OrderByComparator"
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
099 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
100 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
102 new String[] { Long.class.getName() },
103 MBThreadModelImpl.GROUPID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
105 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
107 new String[] { Long.class.getName() });
108 public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
109 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
110 FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
111 new String[] { Long.class.getName() },
112 MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
113 public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
114 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
116 new String[] { Long.class.getName() });
117 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
118 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
119 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
120 new String[] {
121 Long.class.getName(), Long.class.getName(),
122
123 "java.lang.Integer", "java.lang.Integer",
124 "com.liferay.portal.kernel.util.OrderByComparator"
125 });
126 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
127 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
129 new String[] { Long.class.getName(), Long.class.getName() },
130 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
131 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK);
132 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
133 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
134 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
135 new String[] { Long.class.getName(), Long.class.getName() });
136 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
137 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
138 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
139 new String[] { Long.class.getName(), Long.class.getName() });
140 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
141 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
142 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
143 new String[] {
144 Long.class.getName(), Long.class.getName(),
145
146 "java.lang.Integer", "java.lang.Integer",
147 "com.liferay.portal.kernel.util.OrderByComparator"
148 });
149 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC =
150 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
151 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
152 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_NotC",
153 new String[] { Long.class.getName(), Long.class.getName() },
154 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
155 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK);
156 public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
157 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
158 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_NotC",
159 new String[] { Long.class.getName(), Long.class.getName() });
160 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
161 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
162 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
163 new String[] {
164 Long.class.getName(), Integer.class.getName(),
165
166 "java.lang.Integer", "java.lang.Integer",
167 "com.liferay.portal.kernel.util.OrderByComparator"
168 });
169 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
170 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
171 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
172 new String[] { Long.class.getName(), Integer.class.getName() },
173 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
174 MBThreadModelImpl.STATUS_COLUMN_BITMASK);
175 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
176 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
177 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
178 new String[] { Long.class.getName(), Integer.class.getName() });
179 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
180 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
181 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
182 new String[] {
183 Long.class.getName(), Double.class.getName(),
184
185 "java.lang.Integer", "java.lang.Integer",
186 "com.liferay.portal.kernel.util.OrderByComparator"
187 });
188 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
189 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
190 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
191 new String[] { Long.class.getName(), Double.class.getName() },
192 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
193 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
194 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
195 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
196 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
197 new String[] { Long.class.getName(), Double.class.getName() });
198 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
199 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
200 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
201 new String[] {
202 Date.class.getName(), Double.class.getName(),
203
204 "java.lang.Integer", "java.lang.Integer",
205 "com.liferay.portal.kernel.util.OrderByComparator"
206 });
207 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
208 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
209 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
210 new String[] { Date.class.getName(), Double.class.getName() },
211 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
212 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
213 public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
214 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
215 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
216 new String[] { Date.class.getName(), Double.class.getName() });
217 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
218 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
219 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_L",
220 new String[] {
221 Long.class.getName(), Long.class.getName(), Date.class.getName(),
222
223 "java.lang.Integer", "java.lang.Integer",
224 "com.liferay.portal.kernel.util.OrderByComparator"
225 });
226 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
227 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
228 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
229 new String[] {
230 Long.class.getName(), Long.class.getName(), Date.class.getName()
231 },
232 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
233 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
234 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
235 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
236 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
237 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
238 new String[] {
239 Long.class.getName(), Long.class.getName(), Date.class.getName()
240 });
241 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
242 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
243 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
244 new String[] {
245 Long.class.getName(), Long.class.getName(),
246 Integer.class.getName(),
247
248 "java.lang.Integer", "java.lang.Integer",
249 "com.liferay.portal.kernel.util.OrderByComparator"
250 });
251 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
252 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
253 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
254 new String[] {
255 Long.class.getName(), Long.class.getName(),
256 Integer.class.getName()
257 },
258 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
259 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
260 MBThreadModelImpl.STATUS_COLUMN_BITMASK);
261 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
262 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
263 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
264 new String[] {
265 Long.class.getName(), Long.class.getName(),
266 Integer.class.getName()
267 });
268 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
269 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
270 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_S",
271 new String[] {
272 Long.class.getName(), Long.class.getName(),
273 Integer.class.getName()
274 });
275 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
276 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
277 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_S",
278 new String[] {
279 Long.class.getName(), Long.class.getName(),
280 Integer.class.getName(),
281
282 "java.lang.Integer", "java.lang.Integer",
283 "com.liferay.portal.kernel.util.OrderByComparator"
284 });
285 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S =
286 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
287 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
288 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_NotC_S",
289 new String[] {
290 Long.class.getName(), Long.class.getName(),
291 Integer.class.getName()
292 },
293 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
294 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
295 MBThreadModelImpl.STATUS_COLUMN_BITMASK);
296 public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
297 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
298 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_NotC_S",
299 new String[] {
300 Long.class.getName(), Long.class.getName(),
301 Integer.class.getName()
302 });
303 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
304 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
305 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
306 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
307 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
308 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
309 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
310 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
311 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
312
313
318 public void cacheResult(MBThread mbThread) {
319 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
320 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
321
322 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
323 new Object[] { Long.valueOf(mbThread.getRootMessageId()) }, mbThread);
324
325 mbThread.resetOriginalValues();
326 }
327
328
333 public void cacheResult(List<MBThread> mbThreads) {
334 for (MBThread mbThread : mbThreads) {
335 if (EntityCacheUtil.getResult(
336 MBThreadModelImpl.ENTITY_CACHE_ENABLED,
337 MBThreadImpl.class, mbThread.getPrimaryKey()) == null) {
338 cacheResult(mbThread);
339 }
340 else {
341 mbThread.resetOriginalValues();
342 }
343 }
344 }
345
346
353 @Override
354 public void clearCache() {
355 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
356 CacheRegistryUtil.clear(MBThreadImpl.class.getName());
357 }
358
359 EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
360
361 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
362 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
363 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
364 }
365
366
373 @Override
374 public void clearCache(MBThread mbThread) {
375 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
376 MBThreadImpl.class, mbThread.getPrimaryKey());
377
378 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
379 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
380
381 clearUniqueFindersCache(mbThread);
382 }
383
384 @Override
385 public void clearCache(List<MBThread> mbThreads) {
386 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
387 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
388
389 for (MBThread mbThread : mbThreads) {
390 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
391 MBThreadImpl.class, mbThread.getPrimaryKey());
392
393 clearUniqueFindersCache(mbThread);
394 }
395 }
396
397 protected void clearUniqueFindersCache(MBThread mbThread) {
398 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
399 new Object[] { Long.valueOf(mbThread.getRootMessageId()) });
400 }
401
402
408 public MBThread create(long threadId) {
409 MBThread mbThread = new MBThreadImpl();
410
411 mbThread.setNew(true);
412 mbThread.setPrimaryKey(threadId);
413
414 return mbThread;
415 }
416
417
425 public MBThread remove(long threadId)
426 throws NoSuchThreadException, SystemException {
427 return remove(Long.valueOf(threadId));
428 }
429
430
438 @Override
439 public MBThread remove(Serializable primaryKey)
440 throws NoSuchThreadException, SystemException {
441 Session session = null;
442
443 try {
444 session = openSession();
445
446 MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
447 primaryKey);
448
449 if (mbThread == null) {
450 if (_log.isWarnEnabled()) {
451 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
452 }
453
454 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
455 primaryKey);
456 }
457
458 return remove(mbThread);
459 }
460 catch (NoSuchThreadException nsee) {
461 throw nsee;
462 }
463 catch (Exception e) {
464 throw processException(e);
465 }
466 finally {
467 closeSession(session);
468 }
469 }
470
471 @Override
472 protected MBThread removeImpl(MBThread mbThread) throws SystemException {
473 mbThread = toUnwrappedModel(mbThread);
474
475 Session session = null;
476
477 try {
478 session = openSession();
479
480 BatchSessionUtil.delete(session, mbThread);
481 }
482 catch (Exception e) {
483 throw processException(e);
484 }
485 finally {
486 closeSession(session);
487 }
488
489 clearCache(mbThread);
490
491 return mbThread;
492 }
493
494 @Override
495 public MBThread updateImpl(
496 com.liferay.portlet.messageboards.model.MBThread mbThread, boolean merge)
497 throws SystemException {
498 mbThread = toUnwrappedModel(mbThread);
499
500 boolean isNew = mbThread.isNew();
501
502 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
503
504 Session session = null;
505
506 try {
507 session = openSession();
508
509 BatchSessionUtil.update(session, mbThread, merge);
510
511 mbThread.setNew(false);
512 }
513 catch (Exception e) {
514 throw processException(e);
515 }
516 finally {
517 closeSession(session);
518 }
519
520 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
521
522 if (isNew || !MBThreadModelImpl.COLUMN_BITMASK_ENABLED) {
523 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
524 }
525 else {
526 if ((mbThreadModelImpl.getColumnBitmask() &
527 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
528 Object[] args = new Object[] {
529 Long.valueOf(mbThreadModelImpl.getOriginalGroupId())
530 };
531
532 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
533 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
534 args);
535
536 args = new Object[] { Long.valueOf(mbThreadModelImpl.getGroupId()) };
537
538 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
539 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
540 args);
541 }
542
543 if ((mbThreadModelImpl.getColumnBitmask() &
544 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
545 Object[] args = new Object[] {
546 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
547 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId())
548 };
549
550 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
551 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
552 args);
553
554 args = new Object[] {
555 Long.valueOf(mbThreadModelImpl.getGroupId()),
556 Long.valueOf(mbThreadModelImpl.getCategoryId())
557 };
558
559 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
560 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
561 args);
562 }
563
564 if ((mbThreadModelImpl.getColumnBitmask() &
565 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC.getColumnBitmask()) != 0) {
566 Object[] args = new Object[] {
567 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
568 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId())
569 };
570
571 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTC, args);
572 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC,
573 args);
574
575 args = new Object[] {
576 Long.valueOf(mbThreadModelImpl.getGroupId()),
577 Long.valueOf(mbThreadModelImpl.getCategoryId())
578 };
579
580 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTC, args);
581 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC,
582 args);
583 }
584
585 if ((mbThreadModelImpl.getColumnBitmask() &
586 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
587 Object[] args = new Object[] {
588 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
589 Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
590 };
591
592 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
593 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
594 args);
595
596 args = new Object[] {
597 Long.valueOf(mbThreadModelImpl.getGroupId()),
598 Integer.valueOf(mbThreadModelImpl.getStatus())
599 };
600
601 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
602 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
603 args);
604 }
605
606 if ((mbThreadModelImpl.getColumnBitmask() &
607 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
608 Object[] args = new Object[] {
609 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
610 Double.valueOf(mbThreadModelImpl.getOriginalPriority())
611 };
612
613 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
614 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
615 args);
616
617 args = new Object[] {
618 Long.valueOf(mbThreadModelImpl.getCategoryId()),
619 Double.valueOf(mbThreadModelImpl.getPriority())
620 };
621
622 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
623 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
624 args);
625 }
626
627 if ((mbThreadModelImpl.getColumnBitmask() &
628 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
629 Object[] args = new Object[] {
630 mbThreadModelImpl.getOriginalLastPostDate(),
631 Double.valueOf(mbThreadModelImpl.getOriginalPriority())
632 };
633
634 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
635 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
636 args);
637
638 args = new Object[] {
639 mbThreadModelImpl.getLastPostDate(),
640 Double.valueOf(mbThreadModelImpl.getPriority())
641 };
642
643 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
644 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
645 args);
646 }
647
648 if ((mbThreadModelImpl.getColumnBitmask() &
649 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
650 Object[] args = new Object[] {
651 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
652 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
653
654 mbThreadModelImpl.getOriginalLastPostDate()
655 };
656
657 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
658 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
659 args);
660
661 args = new Object[] {
662 Long.valueOf(mbThreadModelImpl.getGroupId()),
663 Long.valueOf(mbThreadModelImpl.getCategoryId()),
664
665 mbThreadModelImpl.getLastPostDate()
666 };
667
668 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
669 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
670 args);
671 }
672
673 if ((mbThreadModelImpl.getColumnBitmask() &
674 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
675 Object[] args = new Object[] {
676 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
677 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
678 Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
679 };
680
681 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
682 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
683 args);
684
685 args = new Object[] {
686 Long.valueOf(mbThreadModelImpl.getGroupId()),
687 Long.valueOf(mbThreadModelImpl.getCategoryId()),
688 Integer.valueOf(mbThreadModelImpl.getStatus())
689 };
690
691 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
692 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
693 args);
694 }
695
696 if ((mbThreadModelImpl.getColumnBitmask() &
697 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S.getColumnBitmask()) != 0) {
698 Object[] args = new Object[] {
699 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
700 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
701 Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
702 };
703
704 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTC_S, args);
705 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S,
706 args);
707
708 args = new Object[] {
709 Long.valueOf(mbThreadModelImpl.getGroupId()),
710 Long.valueOf(mbThreadModelImpl.getCategoryId()),
711 Integer.valueOf(mbThreadModelImpl.getStatus())
712 };
713
714 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTC_S, args);
715 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S,
716 args);
717 }
718 }
719
720 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
721 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
722
723 if (isNew) {
724 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
725 new Object[] { Long.valueOf(mbThread.getRootMessageId()) },
726 mbThread);
727 }
728 else {
729 if ((mbThreadModelImpl.getColumnBitmask() &
730 FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
731 Object[] args = new Object[] {
732 Long.valueOf(mbThreadModelImpl.getOriginalRootMessageId())
733 };
734
735 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
736 args);
737 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
738 args);
739
740 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
741 new Object[] { Long.valueOf(mbThread.getRootMessageId()) },
742 mbThread);
743 }
744 }
745
746 return mbThread;
747 }
748
749 protected MBThread toUnwrappedModel(MBThread mbThread) {
750 if (mbThread instanceof MBThreadImpl) {
751 return mbThread;
752 }
753
754 MBThreadImpl mbThreadImpl = new MBThreadImpl();
755
756 mbThreadImpl.setNew(mbThread.isNew());
757 mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
758
759 mbThreadImpl.setThreadId(mbThread.getThreadId());
760 mbThreadImpl.setGroupId(mbThread.getGroupId());
761 mbThreadImpl.setCompanyId(mbThread.getCompanyId());
762 mbThreadImpl.setCategoryId(mbThread.getCategoryId());
763 mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
764 mbThreadImpl.setRootMessageUserId(mbThread.getRootMessageUserId());
765 mbThreadImpl.setMessageCount(mbThread.getMessageCount());
766 mbThreadImpl.setViewCount(mbThread.getViewCount());
767 mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
768 mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
769 mbThreadImpl.setPriority(mbThread.getPriority());
770 mbThreadImpl.setQuestion(mbThread.isQuestion());
771 mbThreadImpl.setStatus(mbThread.getStatus());
772 mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
773 mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
774 mbThreadImpl.setStatusDate(mbThread.getStatusDate());
775
776 return mbThreadImpl;
777 }
778
779
787 @Override
788 public MBThread findByPrimaryKey(Serializable primaryKey)
789 throws NoSuchModelException, SystemException {
790 return findByPrimaryKey(((Long)primaryKey).longValue());
791 }
792
793
801 public MBThread findByPrimaryKey(long threadId)
802 throws NoSuchThreadException, SystemException {
803 MBThread mbThread = fetchByPrimaryKey(threadId);
804
805 if (mbThread == null) {
806 if (_log.isWarnEnabled()) {
807 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
808 }
809
810 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
811 threadId);
812 }
813
814 return mbThread;
815 }
816
817
824 @Override
825 public MBThread fetchByPrimaryKey(Serializable primaryKey)
826 throws SystemException {
827 return fetchByPrimaryKey(((Long)primaryKey).longValue());
828 }
829
830
837 public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
838 MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
839 MBThreadImpl.class, threadId);
840
841 if (mbThread == _nullMBThread) {
842 return null;
843 }
844
845 if (mbThread == null) {
846 Session session = null;
847
848 boolean hasException = false;
849
850 try {
851 session = openSession();
852
853 mbThread = (MBThread)session.get(MBThreadImpl.class,
854 Long.valueOf(threadId));
855 }
856 catch (Exception e) {
857 hasException = true;
858
859 throw processException(e);
860 }
861 finally {
862 if (mbThread != null) {
863 cacheResult(mbThread);
864 }
865 else if (!hasException) {
866 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
867 MBThreadImpl.class, threadId, _nullMBThread);
868 }
869
870 closeSession(session);
871 }
872 }
873
874 return mbThread;
875 }
876
877
884 public List<MBThread> findByGroupId(long groupId) throws SystemException {
885 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
886 }
887
888
901 public List<MBThread> findByGroupId(long groupId, int start, int end)
902 throws SystemException {
903 return findByGroupId(groupId, start, end, null);
904 }
905
906
920 public List<MBThread> findByGroupId(long groupId, int start, int end,
921 OrderByComparator orderByComparator) throws SystemException {
922 FinderPath finderPath = null;
923 Object[] finderArgs = null;
924
925 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
926 (orderByComparator == null)) {
927 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
928 finderArgs = new Object[] { groupId };
929 }
930 else {
931 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
932 finderArgs = new Object[] { groupId, start, end, orderByComparator };
933 }
934
935 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
936 finderArgs, this);
937
938 if ((list != null) && !list.isEmpty()) {
939 for (MBThread mbThread : list) {
940 if ((groupId != mbThread.getGroupId())) {
941 list = null;
942
943 break;
944 }
945 }
946 }
947
948 if (list == null) {
949 StringBundler query = null;
950
951 if (orderByComparator != null) {
952 query = new StringBundler(3 +
953 (orderByComparator.getOrderByFields().length * 3));
954 }
955 else {
956 query = new StringBundler(3);
957 }
958
959 query.append(_SQL_SELECT_MBTHREAD_WHERE);
960
961 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
962
963 if (orderByComparator != null) {
964 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
965 orderByComparator);
966 }
967
968 else {
969 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
970 }
971
972 String sql = query.toString();
973
974 Session session = null;
975
976 try {
977 session = openSession();
978
979 Query q = session.createQuery(sql);
980
981 QueryPos qPos = QueryPos.getInstance(q);
982
983 qPos.add(groupId);
984
985 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
986 end);
987 }
988 catch (Exception e) {
989 throw processException(e);
990 }
991 finally {
992 if (list == null) {
993 FinderCacheUtil.removeResult(finderPath, finderArgs);
994 }
995 else {
996 cacheResult(list);
997
998 FinderCacheUtil.putResult(finderPath, finderArgs, list);
999 }
1000
1001 closeSession(session);
1002 }
1003 }
1004
1005 return list;
1006 }
1007
1008
1021 public MBThread findByGroupId_First(long groupId,
1022 OrderByComparator orderByComparator)
1023 throws NoSuchThreadException, SystemException {
1024 List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
1025
1026 if (list.isEmpty()) {
1027 StringBundler msg = new StringBundler(4);
1028
1029 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1030
1031 msg.append("groupId=");
1032 msg.append(groupId);
1033
1034 msg.append(StringPool.CLOSE_CURLY_BRACE);
1035
1036 throw new NoSuchThreadException(msg.toString());
1037 }
1038 else {
1039 return list.get(0);
1040 }
1041 }
1042
1043
1056 public MBThread findByGroupId_Last(long groupId,
1057 OrderByComparator orderByComparator)
1058 throws NoSuchThreadException, SystemException {
1059 int count = countByGroupId(groupId);
1060
1061 List<MBThread> list = findByGroupId(groupId, count - 1, count,
1062 orderByComparator);
1063
1064 if (list.isEmpty()) {
1065 StringBundler msg = new StringBundler(4);
1066
1067 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1068
1069 msg.append("groupId=");
1070 msg.append(groupId);
1071
1072 msg.append(StringPool.CLOSE_CURLY_BRACE);
1073
1074 throw new NoSuchThreadException(msg.toString());
1075 }
1076 else {
1077 return list.get(0);
1078 }
1079 }
1080
1081
1095 public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
1096 OrderByComparator orderByComparator)
1097 throws NoSuchThreadException, SystemException {
1098 MBThread mbThread = findByPrimaryKey(threadId);
1099
1100 Session session = null;
1101
1102 try {
1103 session = openSession();
1104
1105 MBThread[] array = new MBThreadImpl[3];
1106
1107 array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1108 orderByComparator, true);
1109
1110 array[1] = mbThread;
1111
1112 array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1113 orderByComparator, false);
1114
1115 return array;
1116 }
1117 catch (Exception e) {
1118 throw processException(e);
1119 }
1120 finally {
1121 closeSession(session);
1122 }
1123 }
1124
1125 protected MBThread getByGroupId_PrevAndNext(Session session,
1126 MBThread mbThread, long groupId, OrderByComparator orderByComparator,
1127 boolean previous) {
1128 StringBundler query = null;
1129
1130 if (orderByComparator != null) {
1131 query = new StringBundler(6 +
1132 (orderByComparator.getOrderByFields().length * 6));
1133 }
1134 else {
1135 query = new StringBundler(3);
1136 }
1137
1138 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1139
1140 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1141
1142 if (orderByComparator != null) {
1143 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1144
1145 if (orderByConditionFields.length > 0) {
1146 query.append(WHERE_AND);
1147 }
1148
1149 for (int i = 0; i < orderByConditionFields.length; i++) {
1150 query.append(_ORDER_BY_ENTITY_ALIAS);
1151 query.append(orderByConditionFields[i]);
1152
1153 if ((i + 1) < orderByConditionFields.length) {
1154 if (orderByComparator.isAscending() ^ previous) {
1155 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1156 }
1157 else {
1158 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1159 }
1160 }
1161 else {
1162 if (orderByComparator.isAscending() ^ previous) {
1163 query.append(WHERE_GREATER_THAN);
1164 }
1165 else {
1166 query.append(WHERE_LESSER_THAN);
1167 }
1168 }
1169 }
1170
1171 query.append(ORDER_BY_CLAUSE);
1172
1173 String[] orderByFields = orderByComparator.getOrderByFields();
1174
1175 for (int i = 0; i < orderByFields.length; i++) {
1176 query.append(_ORDER_BY_ENTITY_ALIAS);
1177 query.append(orderByFields[i]);
1178
1179 if ((i + 1) < orderByFields.length) {
1180 if (orderByComparator.isAscending() ^ previous) {
1181 query.append(ORDER_BY_ASC_HAS_NEXT);
1182 }
1183 else {
1184 query.append(ORDER_BY_DESC_HAS_NEXT);
1185 }
1186 }
1187 else {
1188 if (orderByComparator.isAscending() ^ previous) {
1189 query.append(ORDER_BY_ASC);
1190 }
1191 else {
1192 query.append(ORDER_BY_DESC);
1193 }
1194 }
1195 }
1196 }
1197
1198 else {
1199 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1200 }
1201
1202 String sql = query.toString();
1203
1204 Query q = session.createQuery(sql);
1205
1206 q.setFirstResult(0);
1207 q.setMaxResults(2);
1208
1209 QueryPos qPos = QueryPos.getInstance(q);
1210
1211 qPos.add(groupId);
1212
1213 if (orderByComparator != null) {
1214 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1215
1216 for (Object value : values) {
1217 qPos.add(value);
1218 }
1219 }
1220
1221 List<MBThread> list = q.list();
1222
1223 if (list.size() == 2) {
1224 return list.get(1);
1225 }
1226 else {
1227 return null;
1228 }
1229 }
1230
1231
1238 public List<MBThread> filterFindByGroupId(long groupId)
1239 throws SystemException {
1240 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1241 QueryUtil.ALL_POS, null);
1242 }
1243
1244
1257 public List<MBThread> filterFindByGroupId(long groupId, int start, int end)
1258 throws SystemException {
1259 return filterFindByGroupId(groupId, start, end, null);
1260 }
1261
1262
1276 public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
1277 OrderByComparator orderByComparator) throws SystemException {
1278 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1279 return findByGroupId(groupId, start, end, orderByComparator);
1280 }
1281
1282 StringBundler query = null;
1283
1284 if (orderByComparator != null) {
1285 query = new StringBundler(3 +
1286 (orderByComparator.getOrderByFields().length * 3));
1287 }
1288 else {
1289 query = new StringBundler(3);
1290 }
1291
1292 if (getDB().isSupportsInlineDistinct()) {
1293 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1294 }
1295 else {
1296 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1297 }
1298
1299 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1300
1301 if (!getDB().isSupportsInlineDistinct()) {
1302 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1303 }
1304
1305 if (orderByComparator != null) {
1306 if (getDB().isSupportsInlineDistinct()) {
1307 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1308 orderByComparator);
1309 }
1310 else {
1311 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1312 orderByComparator);
1313 }
1314 }
1315
1316 else {
1317 if (getDB().isSupportsInlineDistinct()) {
1318 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1319 }
1320 else {
1321 query.append(MBThreadModelImpl.ORDER_BY_SQL);
1322 }
1323 }
1324
1325 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1326 MBThread.class.getName(),
1327 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1328
1329 Session session = null;
1330
1331 try {
1332 session = openSession();
1333
1334 SQLQuery q = session.createSQLQuery(sql);
1335
1336 if (getDB().isSupportsInlineDistinct()) {
1337 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1338 }
1339 else {
1340 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1341 }
1342
1343 QueryPos qPos = QueryPos.getInstance(q);
1344
1345 qPos.add(groupId);
1346
1347 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
1348 }
1349 catch (Exception e) {
1350 throw processException(e);
1351 }
1352 finally {
1353 closeSession(session);
1354 }
1355 }
1356
1357
1367 public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
1368 long groupId, OrderByComparator orderByComparator)
1369 throws NoSuchThreadException, SystemException {
1370 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1371 return findByGroupId_PrevAndNext(threadId, groupId,
1372 orderByComparator);
1373 }
1374
1375 MBThread mbThread = findByPrimaryKey(threadId);
1376
1377 Session session = null;
1378
1379 try {
1380 session = openSession();
1381
1382 MBThread[] array = new MBThreadImpl[3];
1383
1384 array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
1385 groupId, orderByComparator, true);
1386
1387 array[1] = mbThread;
1388
1389 array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
1390 groupId, orderByComparator, false);
1391
1392 return array;
1393 }
1394 catch (Exception e) {
1395 throw processException(e);
1396 }
1397 finally {
1398 closeSession(session);
1399 }
1400 }
1401
1402 protected MBThread filterGetByGroupId_PrevAndNext(Session session,
1403 MBThread mbThread, long groupId, OrderByComparator orderByComparator,
1404 boolean previous) {
1405 StringBundler query = null;
1406
1407 if (orderByComparator != null) {
1408 query = new StringBundler(6 +
1409 (orderByComparator.getOrderByFields().length * 6));
1410 }
1411 else {
1412 query = new StringBundler(3);
1413 }
1414
1415 if (getDB().isSupportsInlineDistinct()) {
1416 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1417 }
1418 else {
1419 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1420 }
1421
1422 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1423
1424 if (!getDB().isSupportsInlineDistinct()) {
1425 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1426 }
1427
1428 if (orderByComparator != null) {
1429 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1430
1431 if (orderByConditionFields.length > 0) {
1432 query.append(WHERE_AND);
1433 }
1434
1435 for (int i = 0; i < orderByConditionFields.length; i++) {
1436 if (getDB().isSupportsInlineDistinct()) {
1437 query.append(_ORDER_BY_ENTITY_ALIAS);
1438 }
1439 else {
1440 query.append(_ORDER_BY_ENTITY_TABLE);
1441 }
1442
1443 query.append(orderByConditionFields[i]);
1444
1445 if ((i + 1) < orderByConditionFields.length) {
1446 if (orderByComparator.isAscending() ^ previous) {
1447 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1448 }
1449 else {
1450 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1451 }
1452 }
1453 else {
1454 if (orderByComparator.isAscending() ^ previous) {
1455 query.append(WHERE_GREATER_THAN);
1456 }
1457 else {
1458 query.append(WHERE_LESSER_THAN);
1459 }
1460 }
1461 }
1462
1463 query.append(ORDER_BY_CLAUSE);
1464
1465 String[] orderByFields = orderByComparator.getOrderByFields();
1466
1467 for (int i = 0; i < orderByFields.length; i++) {
1468 if (getDB().isSupportsInlineDistinct()) {
1469 query.append(_ORDER_BY_ENTITY_ALIAS);
1470 }
1471 else {
1472 query.append(_ORDER_BY_ENTITY_TABLE);
1473 }
1474
1475 query.append(orderByFields[i]);
1476
1477 if ((i + 1) < orderByFields.length) {
1478 if (orderByComparator.isAscending() ^ previous) {
1479 query.append(ORDER_BY_ASC_HAS_NEXT);
1480 }
1481 else {
1482 query.append(ORDER_BY_DESC_HAS_NEXT);
1483 }
1484 }
1485 else {
1486 if (orderByComparator.isAscending() ^ previous) {
1487 query.append(ORDER_BY_ASC);
1488 }
1489 else {
1490 query.append(ORDER_BY_DESC);
1491 }
1492 }
1493 }
1494 }
1495
1496 else {
1497 if (getDB().isSupportsInlineDistinct()) {
1498 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1499 }
1500 else {
1501 query.append(MBThreadModelImpl.ORDER_BY_SQL);
1502 }
1503 }
1504
1505 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1506 MBThread.class.getName(),
1507 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1508
1509 SQLQuery q = session.createSQLQuery(sql);
1510
1511 q.setFirstResult(0);
1512 q.setMaxResults(2);
1513
1514 if (getDB().isSupportsInlineDistinct()) {
1515 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1516 }
1517 else {
1518 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1519 }
1520
1521 QueryPos qPos = QueryPos.getInstance(q);
1522
1523 qPos.add(groupId);
1524
1525 if (orderByComparator != null) {
1526 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1527
1528 for (Object value : values) {
1529 qPos.add(value);
1530 }
1531 }
1532
1533 List<MBThread> list = q.list();
1534
1535 if (list.size() == 2) {
1536 return list.get(1);
1537 }
1538 else {
1539 return null;
1540 }
1541 }
1542
1543
1551 public MBThread findByRootMessageId(long rootMessageId)
1552 throws NoSuchThreadException, SystemException {
1553 MBThread mbThread = fetchByRootMessageId(rootMessageId);
1554
1555 if (mbThread == null) {
1556 StringBundler msg = new StringBundler(4);
1557
1558 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1559
1560 msg.append("rootMessageId=");
1561 msg.append(rootMessageId);
1562
1563 msg.append(StringPool.CLOSE_CURLY_BRACE);
1564
1565 if (_log.isWarnEnabled()) {
1566 _log.warn(msg.toString());
1567 }
1568
1569 throw new NoSuchThreadException(msg.toString());
1570 }
1571
1572 return mbThread;
1573 }
1574
1575
1582 public MBThread fetchByRootMessageId(long rootMessageId)
1583 throws SystemException {
1584 return fetchByRootMessageId(rootMessageId, true);
1585 }
1586
1587
1595 public MBThread fetchByRootMessageId(long rootMessageId,
1596 boolean retrieveFromCache) throws SystemException {
1597 Object[] finderArgs = new Object[] { rootMessageId };
1598
1599 Object result = null;
1600
1601 if (retrieveFromCache) {
1602 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1603 finderArgs, this);
1604 }
1605
1606 if (result instanceof MBThread) {
1607 MBThread mbThread = (MBThread)result;
1608
1609 if ((rootMessageId != mbThread.getRootMessageId())) {
1610 result = null;
1611 }
1612 }
1613
1614 if (result == null) {
1615 StringBundler query = new StringBundler(3);
1616
1617 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1618
1619 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
1620
1621 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1622
1623 String sql = query.toString();
1624
1625 Session session = null;
1626
1627 try {
1628 session = openSession();
1629
1630 Query q = session.createQuery(sql);
1631
1632 QueryPos qPos = QueryPos.getInstance(q);
1633
1634 qPos.add(rootMessageId);
1635
1636 List<MBThread> list = q.list();
1637
1638 result = list;
1639
1640 MBThread mbThread = null;
1641
1642 if (list.isEmpty()) {
1643 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1644 finderArgs, list);
1645 }
1646 else {
1647 mbThread = list.get(0);
1648
1649 cacheResult(mbThread);
1650
1651 if ((mbThread.getRootMessageId() != rootMessageId)) {
1652 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1653 finderArgs, mbThread);
1654 }
1655 }
1656
1657 return mbThread;
1658 }
1659 catch (Exception e) {
1660 throw processException(e);
1661 }
1662 finally {
1663 if (result == null) {
1664 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1665 finderArgs);
1666 }
1667
1668 closeSession(session);
1669 }
1670 }
1671 else {
1672 if (result instanceof List<?>) {
1673 return null;
1674 }
1675 else {
1676 return (MBThread)result;
1677 }
1678 }
1679 }
1680
1681
1689 public List<MBThread> findByG_C(long groupId, long categoryId)
1690 throws SystemException {
1691 return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
1692 QueryUtil.ALL_POS, null);
1693 }
1694
1695
1709 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
1710 int end) throws SystemException {
1711 return findByG_C(groupId, categoryId, start, end, null);
1712 }
1713
1714
1729 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
1730 int end, OrderByComparator orderByComparator) throws SystemException {
1731 FinderPath finderPath = null;
1732 Object[] finderArgs = null;
1733
1734 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1735 (orderByComparator == null)) {
1736 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
1737 finderArgs = new Object[] { groupId, categoryId };
1738 }
1739 else {
1740 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
1741 finderArgs = new Object[] {
1742 groupId, categoryId,
1743
1744 start, end, orderByComparator
1745 };
1746 }
1747
1748 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
1749 finderArgs, this);
1750
1751 if ((list != null) && !list.isEmpty()) {
1752 for (MBThread mbThread : list) {
1753 if ((groupId != mbThread.getGroupId()) ||
1754 (categoryId != mbThread.getCategoryId())) {
1755 list = null;
1756
1757 break;
1758 }
1759 }
1760 }
1761
1762 if (list == null) {
1763 StringBundler query = null;
1764
1765 if (orderByComparator != null) {
1766 query = new StringBundler(4 +
1767 (orderByComparator.getOrderByFields().length * 3));
1768 }
1769 else {
1770 query = new StringBundler(4);
1771 }
1772
1773 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1774
1775 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1776
1777 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1778
1779 if (orderByComparator != null) {
1780 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1781 orderByComparator);
1782 }
1783
1784 else {
1785 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1786 }
1787
1788 String sql = query.toString();
1789
1790 Session session = null;
1791
1792 try {
1793 session = openSession();
1794
1795 Query q = session.createQuery(sql);
1796
1797 QueryPos qPos = QueryPos.getInstance(q);
1798
1799 qPos.add(groupId);
1800
1801 qPos.add(categoryId);
1802
1803 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1804 end);
1805 }
1806 catch (Exception e) {
1807 throw processException(e);
1808 }
1809 finally {
1810 if (list == null) {
1811 FinderCacheUtil.removeResult(finderPath, finderArgs);
1812 }
1813 else {
1814 cacheResult(list);
1815
1816 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1817 }
1818
1819 closeSession(session);
1820 }
1821 }
1822
1823 return list;
1824 }
1825
1826
1840 public MBThread findByG_C_First(long groupId, long categoryId,
1841 OrderByComparator orderByComparator)
1842 throws NoSuchThreadException, SystemException {
1843 List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
1844 orderByComparator);
1845
1846 if (list.isEmpty()) {
1847 StringBundler msg = new StringBundler(6);
1848
1849 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1850
1851 msg.append("groupId=");
1852 msg.append(groupId);
1853
1854 msg.append(", categoryId=");
1855 msg.append(categoryId);
1856
1857 msg.append(StringPool.CLOSE_CURLY_BRACE);
1858
1859 throw new NoSuchThreadException(msg.toString());
1860 }
1861 else {
1862 return list.get(0);
1863 }
1864 }
1865
1866
1880 public MBThread findByG_C_Last(long groupId, long categoryId,
1881 OrderByComparator orderByComparator)
1882 throws NoSuchThreadException, SystemException {
1883 int count = countByG_C(groupId, categoryId);
1884
1885 List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
1886 orderByComparator);
1887
1888 if (list.isEmpty()) {
1889 StringBundler msg = new StringBundler(6);
1890
1891 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1892
1893 msg.append("groupId=");
1894 msg.append(groupId);
1895
1896 msg.append(", categoryId=");
1897 msg.append(categoryId);
1898
1899 msg.append(StringPool.CLOSE_CURLY_BRACE);
1900
1901 throw new NoSuchThreadException(msg.toString());
1902 }
1903 else {
1904 return list.get(0);
1905 }
1906 }
1907
1908
1923 public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
1924 long categoryId, OrderByComparator orderByComparator)
1925 throws NoSuchThreadException, SystemException {
1926 MBThread mbThread = findByPrimaryKey(threadId);
1927
1928 Session session = null;
1929
1930 try {
1931 session = openSession();
1932
1933 MBThread[] array = new MBThreadImpl[3];
1934
1935 array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
1936 categoryId, orderByComparator, true);
1937
1938 array[1] = mbThread;
1939
1940 array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
1941 categoryId, orderByComparator, false);
1942
1943 return array;
1944 }
1945 catch (Exception e) {
1946 throw processException(e);
1947 }
1948 finally {
1949 closeSession(session);
1950 }
1951 }
1952
1953 protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
1954 long groupId, long categoryId, OrderByComparator orderByComparator,
1955 boolean previous) {
1956 StringBundler query = null;
1957
1958 if (orderByComparator != null) {
1959 query = new StringBundler(6 +
1960 (orderByComparator.getOrderByFields().length * 6));
1961 }
1962 else {
1963 query = new StringBundler(3);
1964 }
1965
1966 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1967
1968 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1969
1970 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1971
1972 if (orderByComparator != null) {
1973 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1974
1975 if (orderByConditionFields.length > 0) {
1976 query.append(WHERE_AND);
1977 }
1978
1979 for (int i = 0; i < orderByConditionFields.length; i++) {
1980 query.append(_ORDER_BY_ENTITY_ALIAS);
1981 query.append(orderByConditionFields[i]);
1982
1983 if ((i + 1) < orderByConditionFields.length) {
1984 if (orderByComparator.isAscending() ^ previous) {
1985 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1986 }
1987 else {
1988 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1989 }
1990 }
1991 else {
1992 if (orderByComparator.isAscending() ^ previous) {
1993 query.append(WHERE_GREATER_THAN);
1994 }
1995 else {
1996 query.append(WHERE_LESSER_THAN);
1997 }
1998 }
1999 }
2000
2001 query.append(ORDER_BY_CLAUSE);
2002
2003 String[] orderByFields = orderByComparator.getOrderByFields();
2004
2005 for (int i = 0; i < orderByFields.length; i++) {
2006 query.append(_ORDER_BY_ENTITY_ALIAS);
2007 query.append(orderByFields[i]);
2008
2009 if ((i + 1) < orderByFields.length) {
2010 if (orderByComparator.isAscending() ^ previous) {
2011 query.append(ORDER_BY_ASC_HAS_NEXT);
2012 }
2013 else {
2014 query.append(ORDER_BY_DESC_HAS_NEXT);
2015 }
2016 }
2017 else {
2018 if (orderByComparator.isAscending() ^ previous) {
2019 query.append(ORDER_BY_ASC);
2020 }
2021 else {
2022 query.append(ORDER_BY_DESC);
2023 }
2024 }
2025 }
2026 }
2027
2028 else {
2029 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2030 }
2031
2032 String sql = query.toString();
2033
2034 Query q = session.createQuery(sql);
2035
2036 q.setFirstResult(0);
2037 q.setMaxResults(2);
2038
2039 QueryPos qPos = QueryPos.getInstance(q);
2040
2041 qPos.add(groupId);
2042
2043 qPos.add(categoryId);
2044
2045 if (orderByComparator != null) {
2046 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2047
2048 for (Object value : values) {
2049 qPos.add(value);
2050 }
2051 }
2052
2053 List<MBThread> list = q.list();
2054
2055 if (list.size() == 2) {
2056 return list.get(1);
2057 }
2058 else {
2059 return null;
2060 }
2061 }
2062
2063
2075 public List<MBThread> findByG_C(long groupId, long[] categoryIds)
2076 throws SystemException {
2077 return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
2078 QueryUtil.ALL_POS, null);
2079 }
2080
2081
2095 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
2096 int start, int end) throws SystemException {
2097 return findByG_C(groupId, categoryIds, start, end, null);
2098 }
2099
2100
2115 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
2116 int start, int end, OrderByComparator orderByComparator)
2117 throws SystemException {
2118 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
2119 Object[] finderArgs = null;
2120
2121 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2122 (orderByComparator == null)) {
2123 finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
2124 }
2125 else {
2126 finderArgs = new Object[] {
2127 groupId, StringUtil.merge(categoryIds),
2128
2129 start, end, orderByComparator
2130 };
2131 }
2132
2133 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2134 finderArgs, this);
2135
2136 if ((list != null) && !list.isEmpty()) {
2137 for (MBThread mbThread : list) {
2138 if ((groupId != mbThread.getGroupId()) ||
2139 !ArrayUtil.contains(categoryIds,
2140 mbThread.getCategoryId())) {
2141 list = null;
2142
2143 break;
2144 }
2145 }
2146 }
2147
2148 if (list == null) {
2149 StringBundler query = new StringBundler();
2150
2151 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2152
2153 boolean conjunctionable = false;
2154
2155 if (conjunctionable) {
2156 query.append(WHERE_AND);
2157 }
2158
2159 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2160
2161 conjunctionable = true;
2162
2163 if ((categoryIds == null) || (categoryIds.length > 0)) {
2164 if (conjunctionable) {
2165 query.append(WHERE_AND);
2166 }
2167
2168 query.append(StringPool.OPEN_PARENTHESIS);
2169
2170 for (int i = 0; i < categoryIds.length; i++) {
2171 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2172
2173 if ((i + 1) < categoryIds.length) {
2174 query.append(WHERE_OR);
2175 }
2176 }
2177
2178 query.append(StringPool.CLOSE_PARENTHESIS);
2179
2180 conjunctionable = true;
2181 }
2182
2183 if (orderByComparator != null) {
2184 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2185 orderByComparator);
2186 }
2187
2188 else {
2189 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2190 }
2191
2192 String sql = query.toString();
2193
2194 Session session = null;
2195
2196 try {
2197 session = openSession();
2198
2199 Query q = session.createQuery(sql);
2200
2201 QueryPos qPos = QueryPos.getInstance(q);
2202
2203 qPos.add(groupId);
2204
2205 if (categoryIds != null) {
2206 qPos.add(categoryIds);
2207 }
2208
2209 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2210 end);
2211 }
2212 catch (Exception e) {
2213 throw processException(e);
2214 }
2215 finally {
2216 if (list == null) {
2217 FinderCacheUtil.removeResult(finderPath, finderArgs);
2218 }
2219 else {
2220 cacheResult(list);
2221
2222 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2223 }
2224
2225 closeSession(session);
2226 }
2227 }
2228
2229 return list;
2230 }
2231
2232
2240 public List<MBThread> filterFindByG_C(long groupId, long categoryId)
2241 throws SystemException {
2242 return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2243 QueryUtil.ALL_POS, null);
2244 }
2245
2246
2260 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2261 int start, int end) throws SystemException {
2262 return filterFindByG_C(groupId, categoryId, start, end, null);
2263 }
2264
2265
2280 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2281 int start, int end, OrderByComparator orderByComparator)
2282 throws SystemException {
2283 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2284 return findByG_C(groupId, categoryId, start, end, orderByComparator);
2285 }
2286
2287 StringBundler query = null;
2288
2289 if (orderByComparator != null) {
2290 query = new StringBundler(4 +
2291 (orderByComparator.getOrderByFields().length * 3));
2292 }
2293 else {
2294 query = new StringBundler(4);
2295 }
2296
2297 if (getDB().isSupportsInlineDistinct()) {
2298 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2299 }
2300 else {
2301 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2302 }
2303
2304 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2305
2306 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2307
2308 if (!getDB().isSupportsInlineDistinct()) {
2309 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2310 }
2311
2312 if (orderByComparator != null) {
2313 if (getDB().isSupportsInlineDistinct()) {
2314 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2315 orderByComparator);
2316 }
2317 else {
2318 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2319 orderByComparator);
2320 }
2321 }
2322
2323 else {
2324 if (getDB().isSupportsInlineDistinct()) {
2325 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2326 }
2327 else {
2328 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2329 }
2330 }
2331
2332 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2333 MBThread.class.getName(),
2334 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2335
2336 Session session = null;
2337
2338 try {
2339 session = openSession();
2340
2341 SQLQuery q = session.createSQLQuery(sql);
2342
2343 if (getDB().isSupportsInlineDistinct()) {
2344 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2345 }
2346 else {
2347 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2348 }
2349
2350 QueryPos qPos = QueryPos.getInstance(q);
2351
2352 qPos.add(groupId);
2353
2354 qPos.add(categoryId);
2355
2356 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
2357 }
2358 catch (Exception e) {
2359 throw processException(e);
2360 }
2361 finally {
2362 closeSession(session);
2363 }
2364 }
2365
2366
2377 public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
2378 long categoryId, OrderByComparator orderByComparator)
2379 throws NoSuchThreadException, SystemException {
2380 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2381 return findByG_C_PrevAndNext(threadId, groupId, categoryId,
2382 orderByComparator);
2383 }
2384
2385 MBThread mbThread = findByPrimaryKey(threadId);
2386
2387 Session session = null;
2388
2389 try {
2390 session = openSession();
2391
2392 MBThread[] array = new MBThreadImpl[3];
2393
2394 array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
2395 categoryId, orderByComparator, true);
2396
2397 array[1] = mbThread;
2398
2399 array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
2400 categoryId, orderByComparator, false);
2401
2402 return array;
2403 }
2404 catch (Exception e) {
2405 throw processException(e);
2406 }
2407 finally {
2408 closeSession(session);
2409 }
2410 }
2411
2412 protected MBThread filterGetByG_C_PrevAndNext(Session session,
2413 MBThread mbThread, long groupId, long categoryId,
2414 OrderByComparator orderByComparator, boolean previous) {
2415 StringBundler query = null;
2416
2417 if (orderByComparator != null) {
2418 query = new StringBundler(6 +
2419 (orderByComparator.getOrderByFields().length * 6));
2420 }
2421 else {
2422 query = new StringBundler(3);
2423 }
2424
2425 if (getDB().isSupportsInlineDistinct()) {
2426 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2427 }
2428 else {
2429 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2430 }
2431
2432 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2433
2434 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2435
2436 if (!getDB().isSupportsInlineDistinct()) {
2437 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2438 }
2439
2440 if (orderByComparator != null) {
2441 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2442
2443 if (orderByConditionFields.length > 0) {
2444 query.append(WHERE_AND);
2445 }
2446
2447 for (int i = 0; i < orderByConditionFields.length; i++) {
2448 if (getDB().isSupportsInlineDistinct()) {
2449 query.append(_ORDER_BY_ENTITY_ALIAS);
2450 }
2451 else {
2452 query.append(_ORDER_BY_ENTITY_TABLE);
2453 }
2454
2455 query.append(orderByConditionFields[i]);
2456
2457 if ((i + 1) < orderByConditionFields.length) {
2458 if (orderByComparator.isAscending() ^ previous) {
2459 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2460 }
2461 else {
2462 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2463 }
2464 }
2465 else {
2466 if (orderByComparator.isAscending() ^ previous) {
2467 query.append(WHERE_GREATER_THAN);
2468 }
2469 else {
2470 query.append(WHERE_LESSER_THAN);
2471 }
2472 }
2473 }
2474
2475 query.append(ORDER_BY_CLAUSE);
2476
2477 String[] orderByFields = orderByComparator.getOrderByFields();
2478
2479 for (int i = 0; i < orderByFields.length; i++) {
2480 if (getDB().isSupportsInlineDistinct()) {
2481 query.append(_ORDER_BY_ENTITY_ALIAS);
2482 }
2483 else {
2484 query.append(_ORDER_BY_ENTITY_TABLE);
2485 }
2486
2487 query.append(orderByFields[i]);
2488
2489 if ((i + 1) < orderByFields.length) {
2490 if (orderByComparator.isAscending() ^ previous) {
2491 query.append(ORDER_BY_ASC_HAS_NEXT);
2492 }
2493 else {
2494 query.append(ORDER_BY_DESC_HAS_NEXT);
2495 }
2496 }
2497 else {
2498 if (orderByComparator.isAscending() ^ previous) {
2499 query.append(ORDER_BY_ASC);
2500 }
2501 else {
2502 query.append(ORDER_BY_DESC);
2503 }
2504 }
2505 }
2506 }
2507
2508 else {
2509 if (getDB().isSupportsInlineDistinct()) {
2510 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2511 }
2512 else {
2513 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2514 }
2515 }
2516
2517 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2518 MBThread.class.getName(),
2519 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2520
2521 SQLQuery q = session.createSQLQuery(sql);
2522
2523 q.setFirstResult(0);
2524 q.setMaxResults(2);
2525
2526 if (getDB().isSupportsInlineDistinct()) {
2527 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2528 }
2529 else {
2530 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2531 }
2532
2533 QueryPos qPos = QueryPos.getInstance(q);
2534
2535 qPos.add(groupId);
2536
2537 qPos.add(categoryId);
2538
2539 if (orderByComparator != null) {
2540 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2541
2542 for (Object value : values) {
2543 qPos.add(value);
2544 }
2545 }
2546
2547 List<MBThread> list = q.list();
2548
2549 if (list.size() == 2) {
2550 return list.get(1);
2551 }
2552 else {
2553 return null;
2554 }
2555 }
2556
2557
2565 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds)
2566 throws SystemException {
2567 return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
2568 QueryUtil.ALL_POS, null);
2569 }
2570
2571
2585 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
2586 int start, int end) throws SystemException {
2587 return filterFindByG_C(groupId, categoryIds, start, end, null);
2588 }
2589
2590
2605 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
2606 int start, int end, OrderByComparator orderByComparator)
2607 throws SystemException {
2608 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2609 return findByG_C(groupId, categoryIds, start, end, orderByComparator);
2610 }
2611
2612 StringBundler query = new StringBundler();
2613
2614 if (getDB().isSupportsInlineDistinct()) {
2615 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2616 }
2617 else {
2618 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2619 }
2620
2621 boolean conjunctionable = false;
2622
2623 if (conjunctionable) {
2624 query.append(WHERE_AND);
2625 }
2626
2627 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2628
2629 conjunctionable = true;
2630
2631 if ((categoryIds == null) || (categoryIds.length > 0)) {
2632 if (conjunctionable) {
2633 query.append(WHERE_AND);
2634 }
2635
2636 query.append(StringPool.OPEN_PARENTHESIS);
2637
2638 for (int i = 0; i < categoryIds.length; i++) {
2639 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2640
2641 if ((i + 1) < categoryIds.length) {
2642 query.append(WHERE_OR);
2643 }
2644 }
2645
2646 query.append(StringPool.CLOSE_PARENTHESIS);
2647
2648 conjunctionable = true;
2649 }
2650
2651 if (!getDB().isSupportsInlineDistinct()) {
2652 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2653 }
2654
2655 if (orderByComparator != null) {
2656 if (getDB().isSupportsInlineDistinct()) {
2657 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2658 orderByComparator);
2659 }
2660 else {
2661 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2662 orderByComparator);
2663 }
2664 }
2665
2666 else {
2667 if (getDB().isSupportsInlineDistinct()) {
2668 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2669 }
2670 else {
2671 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2672 }
2673 }
2674
2675 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2676 MBThread.class.getName(),
2677 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2678
2679 Session session = null;
2680
2681 try {
2682 session = openSession();
2683
2684 SQLQuery q = session.createSQLQuery(sql);
2685
2686 if (getDB().isSupportsInlineDistinct()) {
2687 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2688 }
2689 else {
2690 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2691 }
2692
2693 QueryPos qPos = QueryPos.getInstance(q);
2694
2695 qPos.add(groupId);
2696
2697 if (categoryIds != null) {
2698 qPos.add(categoryIds);
2699 }
2700
2701 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
2702 }
2703 catch (Exception e) {
2704 throw processException(e);
2705 }
2706 finally {
2707 closeSession(session);
2708 }
2709 }
2710
2711
2719 public List<MBThread> findByG_NotC(long groupId, long categoryId)
2720 throws SystemException {
2721 return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
2722 QueryUtil.ALL_POS, null);
2723 }
2724
2725
2739 public List<MBThread> findByG_NotC(long groupId, long categoryId,
2740 int start, int end) throws SystemException {
2741 return findByG_NotC(groupId, categoryId, start, end, null);
2742 }
2743
2744
2759 public List<MBThread> findByG_NotC(long groupId, long categoryId,
2760 int start, int end, OrderByComparator orderByComparator)
2761 throws SystemException {
2762 FinderPath finderPath = null;
2763 Object[] finderArgs = null;
2764
2765 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2766 (orderByComparator == null)) {
2767 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC;
2768 finderArgs = new Object[] { groupId, categoryId };
2769 }
2770 else {
2771 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
2772 finderArgs = new Object[] {
2773 groupId, categoryId,
2774
2775 start, end, orderByComparator
2776 };
2777 }
2778
2779 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2780 finderArgs, this);
2781
2782 if ((list != null) && !list.isEmpty()) {
2783 for (MBThread mbThread : list) {
2784 if ((groupId != mbThread.getGroupId()) ||
2785 (categoryId != mbThread.getCategoryId())) {
2786 list = null;
2787
2788 break;
2789 }
2790 }
2791 }
2792
2793 if (list == null) {
2794 StringBundler query = null;
2795
2796 if (orderByComparator != null) {
2797 query = new StringBundler(4 +
2798 (orderByComparator.getOrderByFields().length * 3));
2799 }
2800 else {
2801 query = new StringBundler(4);
2802 }
2803
2804 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2805
2806 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
2807
2808 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
2809
2810 if (orderByComparator != null) {
2811 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2812 orderByComparator);
2813 }
2814
2815 else {
2816 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2817 }
2818
2819 String sql = query.toString();
2820
2821 Session session = null;
2822
2823 try {
2824 session = openSession();
2825
2826 Query q = session.createQuery(sql);
2827
2828 QueryPos qPos = QueryPos.getInstance(q);
2829
2830 qPos.add(groupId);
2831
2832 qPos.add(categoryId);
2833
2834 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2835 end);
2836 }
2837 catch (Exception e) {
2838 throw processException(e);
2839 }
2840 finally {
2841 if (list == null) {
2842 FinderCacheUtil.removeResult(finderPath, finderArgs);
2843 }
2844 else {
2845 cacheResult(list);
2846
2847 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2848 }
2849
2850 closeSession(session);
2851 }
2852 }
2853
2854 return list;
2855 }
2856
2857
2871 public MBThread findByG_NotC_First(long groupId, long categoryId,
2872 OrderByComparator orderByComparator)
2873 throws NoSuchThreadException, SystemException {
2874 List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
2875 orderByComparator);
2876
2877 if (list.isEmpty()) {
2878 StringBundler msg = new StringBundler(6);
2879
2880 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2881
2882 msg.append("groupId=");
2883 msg.append(groupId);
2884
2885 msg.append(", categoryId=");
2886 msg.append(categoryId);
2887
2888 msg.append(StringPool.CLOSE_CURLY_BRACE);
2889
2890 throw new NoSuchThreadException(msg.toString());
2891 }
2892 else {
2893 return list.get(0);
2894 }
2895 }
2896
2897
2911 public MBThread findByG_NotC_Last(long groupId, long categoryId,
2912 OrderByComparator orderByComparator)
2913 throws NoSuchThreadException, SystemException {
2914 int count = countByG_NotC(groupId, categoryId);
2915
2916 List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
2917 count, orderByComparator);
2918
2919 if (list.isEmpty()) {
2920 StringBundler msg = new StringBundler(6);
2921
2922 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2923
2924 msg.append("groupId=");
2925 msg.append(groupId);
2926
2927 msg.append(", categoryId=");
2928 msg.append(categoryId);
2929
2930 msg.append(StringPool.CLOSE_CURLY_BRACE);
2931
2932 throw new NoSuchThreadException(msg.toString());
2933 }
2934 else {
2935 return list.get(0);
2936 }
2937 }
2938
2939
2954 public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
2955 long categoryId, OrderByComparator orderByComparator)
2956 throws NoSuchThreadException, SystemException {
2957 MBThread mbThread = findByPrimaryKey(threadId);
2958
2959 Session session = null;
2960
2961 try {
2962 session = openSession();
2963
2964 MBThread[] array = new MBThreadImpl[3];
2965
2966 array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
2967 categoryId, orderByComparator, true);
2968
2969 array[1] = mbThread;
2970
2971 array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
2972 categoryId, orderByComparator, false);
2973
2974 return array;
2975 }
2976 catch (Exception e) {
2977 throw processException(e);
2978 }
2979 finally {
2980 closeSession(session);
2981 }
2982 }
2983
2984 protected MBThread getByG_NotC_PrevAndNext(Session session,
2985 MBThread mbThread, long groupId, long categoryId,
2986 OrderByComparator orderByComparator, boolean previous) {
2987 StringBundler query = null;
2988
2989 if (orderByComparator != null) {
2990 query = new StringBundler(6 +
2991 (orderByComparator.getOrderByFields().length * 6));
2992 }
2993 else {
2994 query = new StringBundler(3);
2995 }
2996
2997 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2998
2999 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3000
3001 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3002
3003 if (orderByComparator != null) {
3004 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3005
3006 if (orderByConditionFields.length > 0) {
3007 query.append(WHERE_AND);
3008 }
3009
3010 for (int i = 0; i < orderByConditionFields.length; i++) {
3011 query.append(_ORDER_BY_ENTITY_ALIAS);
3012 query.append(orderByConditionFields[i]);
3013
3014 if ((i + 1) < orderByConditionFields.length) {
3015 if (orderByComparator.isAscending() ^ previous) {
3016 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3017 }
3018 else {
3019 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3020 }
3021 }
3022 else {
3023 if (orderByComparator.isAscending() ^ previous) {
3024 query.append(WHERE_GREATER_THAN);
3025 }
3026 else {
3027 query.append(WHERE_LESSER_THAN);
3028 }
3029 }
3030 }
3031
3032 query.append(ORDER_BY_CLAUSE);
3033
3034 String[] orderByFields = orderByComparator.getOrderByFields();
3035
3036 for (int i = 0; i < orderByFields.length; i++) {
3037 query.append(_ORDER_BY_ENTITY_ALIAS);
3038 query.append(orderByFields[i]);
3039
3040 if ((i + 1) < orderByFields.length) {
3041 if (orderByComparator.isAscending() ^ previous) {
3042 query.append(ORDER_BY_ASC_HAS_NEXT);
3043 }
3044 else {
3045 query.append(ORDER_BY_DESC_HAS_NEXT);
3046 }
3047 }
3048 else {
3049 if (orderByComparator.isAscending() ^ previous) {
3050 query.append(ORDER_BY_ASC);
3051 }
3052 else {
3053 query.append(ORDER_BY_DESC);
3054 }
3055 }
3056 }
3057 }
3058
3059 else {
3060 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3061 }
3062
3063 String sql = query.toString();
3064
3065 Query q = session.createQuery(sql);
3066
3067 q.setFirstResult(0);
3068 q.setMaxResults(2);
3069
3070 QueryPos qPos = QueryPos.getInstance(q);
3071
3072 qPos.add(groupId);
3073
3074 qPos.add(categoryId);
3075
3076 if (orderByComparator != null) {
3077 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3078
3079 for (Object value : values) {
3080 qPos.add(value);
3081 }
3082 }
3083
3084 List<MBThread> list = q.list();
3085
3086 if (list.size() == 2) {
3087 return list.get(1);
3088 }
3089 else {
3090 return null;
3091 }
3092 }
3093
3094
3102 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId)
3103 throws SystemException {
3104 return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
3105 QueryUtil.ALL_POS, null);
3106 }
3107
3108
3122 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
3123 int start, int end) throws SystemException {
3124 return filterFindByG_NotC(groupId, categoryId, start, end, null);
3125 }
3126
3127
3142 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
3143 int start, int end, OrderByComparator orderByComparator)
3144 throws SystemException {
3145 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3146 return findByG_NotC(groupId, categoryId, start, end,
3147 orderByComparator);
3148 }
3149
3150 StringBundler query = null;
3151
3152 if (orderByComparator != null) {
3153 query = new StringBundler(4 +
3154 (orderByComparator.getOrderByFields().length * 3));
3155 }
3156 else {
3157 query = new StringBundler(4);
3158 }
3159
3160 if (getDB().isSupportsInlineDistinct()) {
3161 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3162 }
3163 else {
3164 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3165 }
3166
3167 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3168
3169 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3170
3171 if (!getDB().isSupportsInlineDistinct()) {
3172 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3173 }
3174
3175 if (orderByComparator != null) {
3176 if (getDB().isSupportsInlineDistinct()) {
3177 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3178 orderByComparator);
3179 }
3180 else {
3181 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3182 orderByComparator);
3183 }
3184 }
3185
3186 else {
3187 if (getDB().isSupportsInlineDistinct()) {
3188 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3189 }
3190 else {
3191 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3192 }
3193 }
3194
3195 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3196 MBThread.class.getName(),
3197 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3198
3199 Session session = null;
3200
3201 try {
3202 session = openSession();
3203
3204 SQLQuery q = session.createSQLQuery(sql);
3205
3206 if (getDB().isSupportsInlineDistinct()) {
3207 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3208 }
3209 else {
3210 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3211 }
3212
3213 QueryPos qPos = QueryPos.getInstance(q);
3214
3215 qPos.add(groupId);
3216
3217 qPos.add(categoryId);
3218
3219 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3220 }
3221 catch (Exception e) {
3222 throw processException(e);
3223 }
3224 finally {
3225 closeSession(session);
3226 }
3227 }
3228
3229
3240 public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
3241 long groupId, long categoryId, OrderByComparator orderByComparator)
3242 throws NoSuchThreadException, SystemException {
3243 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3244 return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
3245 orderByComparator);
3246 }
3247
3248 MBThread mbThread = findByPrimaryKey(threadId);
3249
3250 Session session = null;
3251
3252 try {
3253 session = openSession();
3254
3255 MBThread[] array = new MBThreadImpl[3];
3256
3257 array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
3258 groupId, categoryId, orderByComparator, true);
3259
3260 array[1] = mbThread;
3261
3262 array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
3263 groupId, categoryId, orderByComparator, false);
3264
3265 return array;
3266 }
3267 catch (Exception e) {
3268 throw processException(e);
3269 }
3270 finally {
3271 closeSession(session);
3272 }
3273 }
3274
3275 protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
3276 MBThread mbThread, long groupId, long categoryId,
3277 OrderByComparator orderByComparator, boolean previous) {
3278 StringBundler query = null;
3279
3280 if (orderByComparator != null) {
3281 query = new StringBundler(6 +
3282 (orderByComparator.getOrderByFields().length * 6));
3283 }
3284 else {
3285 query = new StringBundler(3);
3286 }
3287
3288 if (getDB().isSupportsInlineDistinct()) {
3289 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3290 }
3291 else {
3292 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3293 }
3294
3295 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3296
3297 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3298
3299 if (!getDB().isSupportsInlineDistinct()) {
3300 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3301 }
3302
3303 if (orderByComparator != null) {
3304 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3305
3306 if (orderByConditionFields.length > 0) {
3307 query.append(WHERE_AND);
3308 }
3309
3310 for (int i = 0; i < orderByConditionFields.length; i++) {
3311 if (getDB().isSupportsInlineDistinct()) {
3312 query.append(_ORDER_BY_ENTITY_ALIAS);
3313 }
3314 else {
3315 query.append(_ORDER_BY_ENTITY_TABLE);
3316 }
3317
3318 query.append(orderByConditionFields[i]);
3319
3320 if ((i + 1) < orderByConditionFields.length) {
3321 if (orderByComparator.isAscending() ^ previous) {
3322 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3323 }
3324 else {
3325 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3326 }
3327 }
3328 else {
3329 if (orderByComparator.isAscending() ^ previous) {
3330 query.append(WHERE_GREATER_THAN);
3331 }
3332 else {
3333 query.append(WHERE_LESSER_THAN);
3334 }
3335 }
3336 }
3337
3338 query.append(ORDER_BY_CLAUSE);
3339
3340 String[] orderByFields = orderByComparator.getOrderByFields();
3341
3342 for (int i = 0; i < orderByFields.length; i++) {
3343 if (getDB().isSupportsInlineDistinct()) {
3344 query.append(_ORDER_BY_ENTITY_ALIAS);
3345 }
3346 else {
3347 query.append(_ORDER_BY_ENTITY_TABLE);
3348 }
3349
3350 query.append(orderByFields[i]);
3351
3352 if ((i + 1) < orderByFields.length) {
3353 if (orderByComparator.isAscending() ^ previous) {
3354 query.append(ORDER_BY_ASC_HAS_NEXT);
3355 }
3356 else {
3357 query.append(ORDER_BY_DESC_HAS_NEXT);
3358 }
3359 }
3360 else {
3361 if (orderByComparator.isAscending() ^ previous) {
3362 query.append(ORDER_BY_ASC);
3363 }
3364 else {
3365 query.append(ORDER_BY_DESC);
3366 }
3367 }
3368 }
3369 }
3370
3371 else {
3372 if (getDB().isSupportsInlineDistinct()) {
3373 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3374 }
3375 else {
3376 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3377 }
3378 }
3379
3380 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3381 MBThread.class.getName(),
3382 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3383
3384 SQLQuery q = session.createSQLQuery(sql);
3385
3386 q.setFirstResult(0);
3387 q.setMaxResults(2);
3388
3389 if (getDB().isSupportsInlineDistinct()) {
3390 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3391 }
3392 else {
3393 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3394 }
3395
3396 QueryPos qPos = QueryPos.getInstance(q);
3397
3398 qPos.add(groupId);
3399
3400 qPos.add(categoryId);
3401
3402 if (orderByComparator != null) {
3403 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3404
3405 for (Object value : values) {
3406 qPos.add(value);
3407 }
3408 }
3409
3410 List<MBThread> list = q.list();
3411
3412 if (list.size() == 2) {
3413 return list.get(1);
3414 }
3415 else {
3416 return null;
3417 }
3418 }
3419
3420
3428 public List<MBThread> findByG_S(long groupId, int status)
3429 throws SystemException {
3430 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3431 null);
3432 }
3433
3434
3448 public List<MBThread> findByG_S(long groupId, int status, int start, int end)
3449 throws SystemException {
3450 return findByG_S(groupId, status, start, end, null);
3451 }
3452
3453
3468 public List<MBThread> findByG_S(long groupId, int status, int start,
3469 int end, OrderByComparator orderByComparator) throws SystemException {
3470 FinderPath finderPath = null;
3471 Object[] finderArgs = null;
3472
3473 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3474 (orderByComparator == null)) {
3475 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
3476 finderArgs = new Object[] { groupId, status };
3477 }
3478 else {
3479 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
3480 finderArgs = new Object[] {
3481 groupId, status,
3482
3483 start, end, orderByComparator
3484 };
3485 }
3486
3487 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
3488 finderArgs, this);
3489
3490 if ((list != null) && !list.isEmpty()) {
3491 for (MBThread mbThread : list) {
3492 if ((groupId != mbThread.getGroupId()) ||
3493 (status != mbThread.getStatus())) {
3494 list = null;
3495
3496 break;
3497 }
3498 }
3499 }
3500
3501 if (list == null) {
3502 StringBundler query = null;
3503
3504 if (orderByComparator != null) {
3505 query = new StringBundler(4 +
3506 (orderByComparator.getOrderByFields().length * 3));
3507 }
3508 else {
3509 query = new StringBundler(4);
3510 }
3511
3512 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3513
3514 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3515
3516 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3517
3518 if (orderByComparator != null) {
3519 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3520 orderByComparator);
3521 }
3522
3523 else {
3524 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3525 }
3526
3527 String sql = query.toString();
3528
3529 Session session = null;
3530
3531 try {
3532 session = openSession();
3533
3534 Query q = session.createQuery(sql);
3535
3536 QueryPos qPos = QueryPos.getInstance(q);
3537
3538 qPos.add(groupId);
3539
3540 qPos.add(status);
3541
3542 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
3543 end);
3544 }
3545 catch (Exception e) {
3546 throw processException(e);
3547 }
3548 finally {
3549 if (list == null) {
3550 FinderCacheUtil.removeResult(finderPath, finderArgs);
3551 }
3552 else {
3553 cacheResult(list);
3554
3555 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3556 }
3557
3558 closeSession(session);
3559 }
3560 }
3561
3562 return list;
3563 }
3564
3565
3579 public MBThread findByG_S_First(long groupId, int status,
3580 OrderByComparator orderByComparator)
3581 throws NoSuchThreadException, SystemException {
3582 List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
3583
3584 if (list.isEmpty()) {
3585 StringBundler msg = new StringBundler(6);
3586
3587 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3588
3589 msg.append("groupId=");
3590 msg.append(groupId);
3591
3592 msg.append(", status=");
3593 msg.append(status);
3594
3595 msg.append(StringPool.CLOSE_CURLY_BRACE);
3596
3597 throw new NoSuchThreadException(msg.toString());
3598 }
3599 else {
3600 return list.get(0);
3601 }
3602 }
3603
3604
3618 public MBThread findByG_S_Last(long groupId, int status,
3619 OrderByComparator orderByComparator)
3620 throws NoSuchThreadException, SystemException {
3621 int count = countByG_S(groupId, status);
3622
3623 List<MBThread> list = findByG_S(groupId, status, count - 1, count,
3624 orderByComparator);
3625
3626 if (list.isEmpty()) {
3627 StringBundler msg = new StringBundler(6);
3628
3629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3630
3631 msg.append("groupId=");
3632 msg.append(groupId);
3633
3634 msg.append(", status=");
3635 msg.append(status);
3636
3637 msg.append(StringPool.CLOSE_CURLY_BRACE);
3638
3639 throw new NoSuchThreadException(msg.toString());
3640 }
3641 else {
3642 return list.get(0);
3643 }
3644 }
3645
3646
3661 public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
3662 int status, OrderByComparator orderByComparator)
3663 throws NoSuchThreadException, SystemException {
3664 MBThread mbThread = findByPrimaryKey(threadId);
3665
3666 Session session = null;
3667
3668 try {
3669 session = openSession();
3670
3671 MBThread[] array = new MBThreadImpl[3];
3672
3673 array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
3674 orderByComparator, true);
3675
3676 array[1] = mbThread;
3677
3678 array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
3679 orderByComparator, false);
3680
3681 return array;
3682 }
3683 catch (Exception e) {
3684 throw processException(e);
3685 }
3686 finally {
3687 closeSession(session);
3688 }
3689 }
3690
3691 protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
3692 long groupId, int status, OrderByComparator orderByComparator,
3693 boolean previous) {
3694 StringBundler query = null;
3695
3696 if (orderByComparator != null) {
3697 query = new StringBundler(6 +
3698 (orderByComparator.getOrderByFields().length * 6));
3699 }
3700 else {
3701 query = new StringBundler(3);
3702 }
3703
3704 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3705
3706 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3707
3708 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3709
3710 if (orderByComparator != null) {
3711 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3712
3713 if (orderByConditionFields.length > 0) {
3714 query.append(WHERE_AND);
3715 }
3716
3717 for (int i = 0; i < orderByConditionFields.length; i++) {
3718 query.append(_ORDER_BY_ENTITY_ALIAS);
3719 query.append(orderByConditionFields[i]);
3720
3721 if ((i + 1) < orderByConditionFields.length) {
3722 if (orderByComparator.isAscending() ^ previous) {
3723 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3724 }
3725 else {
3726 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3727 }
3728 }
3729 else {
3730 if (orderByComparator.isAscending() ^ previous) {
3731 query.append(WHERE_GREATER_THAN);
3732 }
3733 else {
3734 query.append(WHERE_LESSER_THAN);
3735 }
3736 }
3737 }
3738
3739 query.append(ORDER_BY_CLAUSE);
3740
3741 String[] orderByFields = orderByComparator.getOrderByFields();
3742
3743 for (int i = 0; i < orderByFields.length; i++) {
3744 query.append(_ORDER_BY_ENTITY_ALIAS);
3745 query.append(orderByFields[i]);
3746
3747 if ((i + 1) < orderByFields.length) {
3748 if (orderByComparator.isAscending() ^ previous) {
3749 query.append(ORDER_BY_ASC_HAS_NEXT);
3750 }
3751 else {
3752 query.append(ORDER_BY_DESC_HAS_NEXT);
3753 }
3754 }
3755 else {
3756 if (orderByComparator.isAscending() ^ previous) {
3757 query.append(ORDER_BY_ASC);
3758 }
3759 else {
3760 query.append(ORDER_BY_DESC);
3761 }
3762 }
3763 }
3764 }
3765
3766 else {
3767 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3768 }
3769
3770 String sql = query.toString();
3771
3772 Query q = session.createQuery(sql);
3773
3774 q.setFirstResult(0);
3775 q.setMaxResults(2);
3776
3777 QueryPos qPos = QueryPos.getInstance(q);
3778
3779 qPos.add(groupId);
3780
3781 qPos.add(status);
3782
3783 if (orderByComparator != null) {
3784 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3785
3786 for (Object value : values) {
3787 qPos.add(value);
3788 }
3789 }
3790
3791 List<MBThread> list = q.list();
3792
3793 if (list.size() == 2) {
3794 return list.get(1);
3795 }
3796 else {
3797 return null;
3798 }
3799 }
3800
3801
3809 public List<MBThread> filterFindByG_S(long groupId, int status)
3810 throws SystemException {
3811 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
3812 QueryUtil.ALL_POS, null);
3813 }
3814
3815
3829 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
3830 int end) throws SystemException {
3831 return filterFindByG_S(groupId, status, start, end, null);
3832 }
3833
3834
3849 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
3850 int end, OrderByComparator orderByComparator) throws SystemException {
3851 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3852 return findByG_S(groupId, status, start, end, orderByComparator);
3853 }
3854
3855 StringBundler query = null;
3856
3857 if (orderByComparator != null) {
3858 query = new StringBundler(4 +
3859 (orderByComparator.getOrderByFields().length * 3));
3860 }
3861 else {
3862 query = new StringBundler(4);
3863 }
3864
3865 if (getDB().isSupportsInlineDistinct()) {
3866 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3867 }
3868 else {
3869 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3870 }
3871
3872 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3873
3874 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3875
3876 if (!getDB().isSupportsInlineDistinct()) {
3877 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3878 }
3879
3880 if (orderByComparator != null) {
3881 if (getDB().isSupportsInlineDistinct()) {
3882 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3883 orderByComparator);
3884 }
3885 else {
3886 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3887 orderByComparator);
3888 }
3889 }
3890
3891 else {
3892 if (getDB().isSupportsInlineDistinct()) {
3893 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3894 }
3895 else {
3896 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3897 }
3898 }
3899
3900 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3901 MBThread.class.getName(),
3902 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3903
3904 Session session = null;
3905
3906 try {
3907 session = openSession();
3908
3909 SQLQuery q = session.createSQLQuery(sql);
3910
3911 if (getDB().isSupportsInlineDistinct()) {
3912 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3913 }
3914 else {
3915 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3916 }
3917
3918 QueryPos qPos = QueryPos.getInstance(q);
3919
3920 qPos.add(groupId);
3921
3922 qPos.add(status);
3923
3924 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3925 }
3926 catch (Exception e) {
3927 throw processException(e);
3928 }
3929 finally {
3930 closeSession(session);
3931 }
3932 }
3933
3934
3945 public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
3946 int status, OrderByComparator orderByComparator)
3947 throws NoSuchThreadException, SystemException {
3948 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3949 return findByG_S_PrevAndNext(threadId, groupId, status,
3950 orderByComparator);
3951 }
3952
3953 MBThread mbThread = findByPrimaryKey(threadId);
3954
3955 Session session = null;
3956
3957 try {
3958 session = openSession();
3959
3960 MBThread[] array = new MBThreadImpl[3];
3961
3962 array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
3963 status, orderByComparator, true);
3964
3965 array[1] = mbThread;
3966
3967 array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
3968 status, orderByComparator, false);
3969
3970 return array;
3971 }
3972 catch (Exception e) {
3973 throw processException(e);
3974 }
3975 finally {
3976 closeSession(session);
3977 }
3978 }
3979
3980 protected MBThread filterGetByG_S_PrevAndNext(Session session,
3981 MBThread mbThread, long groupId, int status,
3982 OrderByComparator orderByComparator, boolean previous) {
3983 StringBundler query = null;
3984
3985 if (orderByComparator != null) {
3986 query = new StringBundler(6 +
3987 (orderByComparator.getOrderByFields().length * 6));
3988 }
3989 else {
3990 query = new StringBundler(3);
3991 }
3992
3993 if (getDB().isSupportsInlineDistinct()) {
3994 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3995 }
3996 else {
3997 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3998 }
3999
4000 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4001
4002 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4003
4004 if (!getDB().isSupportsInlineDistinct()) {
4005 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4006 }
4007
4008 if (orderByComparator != null) {
4009 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4010
4011 if (orderByConditionFields.length > 0) {
4012 query.append(WHERE_AND);
4013 }
4014
4015 for (int i = 0; i < orderByConditionFields.length; i++) {
4016 if (getDB().isSupportsInlineDistinct()) {
4017 query.append(_ORDER_BY_ENTITY_ALIAS);
4018 }
4019 else {
4020 query.append(_ORDER_BY_ENTITY_TABLE);
4021 }
4022
4023 query.append(orderByConditionFields[i]);
4024
4025 if ((i + 1) < orderByConditionFields.length) {
4026 if (orderByComparator.isAscending() ^ previous) {
4027 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4028 }
4029 else {
4030 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4031 }
4032 }
4033 else {
4034 if (orderByComparator.isAscending() ^ previous) {
4035 query.append(WHERE_GREATER_THAN);
4036 }
4037 else {
4038 query.append(WHERE_LESSER_THAN);
4039 }
4040 }
4041 }
4042
4043 query.append(ORDER_BY_CLAUSE);
4044
4045 String[] orderByFields = orderByComparator.getOrderByFields();
4046
4047 for (int i = 0; i < orderByFields.length; i++) {
4048 if (getDB().isSupportsInlineDistinct()) {
4049 query.append(_ORDER_BY_ENTITY_ALIAS);
4050 }
4051 else {
4052 query.append(_ORDER_BY_ENTITY_TABLE);
4053 }
4054
4055 query.append(orderByFields[i]);
4056
4057 if ((i + 1) < orderByFields.length) {
4058 if (orderByComparator.isAscending() ^ previous) {
4059 query.append(ORDER_BY_ASC_HAS_NEXT);
4060 }
4061 else {
4062 query.append(ORDER_BY_DESC_HAS_NEXT);
4063 }
4064 }
4065 else {
4066 if (orderByComparator.isAscending() ^ previous) {
4067 query.append(ORDER_BY_ASC);
4068 }
4069 else {
4070 query.append(ORDER_BY_DESC);
4071 }
4072 }
4073 }
4074 }
4075
4076 else {
4077 if (getDB().isSupportsInlineDistinct()) {
4078 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4079 }
4080 else {
4081 query.append(MBThreadModelImpl.ORDER_BY_SQL);
4082 }
4083 }
4084
4085 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4086 MBThread.class.getName(),
4087 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4088
4089 SQLQuery q = session.createSQLQuery(sql);
4090
4091 q.setFirstResult(0);
4092 q.setMaxResults(2);
4093
4094 if (getDB().isSupportsInlineDistinct()) {
4095 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4096 }
4097 else {
4098 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4099 }
4100
4101 QueryPos qPos = QueryPos.getInstance(q);
4102
4103 qPos.add(groupId);
4104
4105 qPos.add(status);
4106
4107 if (orderByComparator != null) {
4108 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4109
4110 for (Object value : values) {
4111 qPos.add(value);
4112 }
4113 }
4114
4115 List<MBThread> list = q.list();
4116
4117 if (list.size() == 2) {
4118 return list.get(1);
4119 }
4120 else {
4121 return null;
4122 }
4123 }
4124
4125
4133 public List<MBThread> findByC_P(long categoryId, double priority)
4134 throws SystemException {
4135 return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
4136 QueryUtil.ALL_POS, null);
4137 }
4138
4139
4153 public List<MBThread> findByC_P(long categoryId, double priority,
4154 int start, int end) throws SystemException {
4155 return findByC_P(categoryId, priority, start, end, null);
4156 }
4157
4158
4173 public List<MBThread> findByC_P(long categoryId, double priority,
4174 int start, int end, OrderByComparator orderByComparator)
4175 throws SystemException {
4176 FinderPath finderPath = null;
4177 Object[] finderArgs = null;
4178
4179 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4180 (orderByComparator == null)) {
4181 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
4182 finderArgs = new Object[] { categoryId, priority };
4183 }
4184 else {
4185 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
4186 finderArgs = new Object[] {
4187 categoryId, priority,
4188
4189 start, end, orderByComparator
4190 };
4191 }
4192
4193 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4194 finderArgs, this);
4195
4196 if ((list != null) && !list.isEmpty()) {
4197 for (MBThread mbThread : list) {
4198 if ((categoryId != mbThread.getCategoryId()) ||
4199 (priority != mbThread.getPriority())) {
4200 list = null;
4201
4202 break;
4203 }
4204 }
4205 }
4206
4207 if (list == null) {
4208 StringBundler query = null;
4209
4210 if (orderByComparator != null) {
4211 query = new StringBundler(4 +
4212 (orderByComparator.getOrderByFields().length * 3));
4213 }
4214 else {
4215 query = new StringBundler(4);
4216 }
4217
4218 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4219
4220 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4221
4222 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4223
4224 if (orderByComparator != null) {
4225 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4226 orderByComparator);
4227 }
4228
4229 else {
4230 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4231 }
4232
4233 String sql = query.toString();
4234
4235 Session session = null;
4236
4237 try {
4238 session = openSession();
4239
4240 Query q = session.createQuery(sql);
4241
4242 QueryPos qPos = QueryPos.getInstance(q);
4243
4244 qPos.add(categoryId);
4245
4246 qPos.add(priority);
4247
4248 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
4249 end);
4250 }
4251 catch (Exception e) {
4252 throw processException(e);
4253 }
4254 finally {
4255 if (list == null) {
4256 FinderCacheUtil.removeResult(finderPath, finderArgs);
4257 }
4258 else {
4259 cacheResult(list);
4260
4261 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4262 }
4263
4264 closeSession(session);
4265 }
4266 }
4267
4268 return list;
4269 }
4270
4271
4285 public MBThread findByC_P_First(long categoryId, double priority,
4286 OrderByComparator orderByComparator)
4287 throws NoSuchThreadException, SystemException {
4288 List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
4289 orderByComparator);
4290
4291 if (list.isEmpty()) {
4292 StringBundler msg = new StringBundler(6);
4293
4294 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4295
4296 msg.append("categoryId=");
4297 msg.append(categoryId);
4298
4299 msg.append(", priority=");
4300 msg.append(priority);
4301
4302 msg.append(StringPool.CLOSE_CURLY_BRACE);
4303
4304 throw new NoSuchThreadException(msg.toString());
4305 }
4306 else {
4307 return list.get(0);
4308 }
4309 }
4310
4311
4325 public MBThread findByC_P_Last(long categoryId, double priority,
4326 OrderByComparator orderByComparator)
4327 throws NoSuchThreadException, SystemException {
4328 int count = countByC_P(categoryId, priority);
4329
4330 List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
4331 orderByComparator);
4332
4333 if (list.isEmpty()) {
4334 StringBundler msg = new StringBundler(6);
4335
4336 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4337
4338 msg.append("categoryId=");
4339 msg.append(categoryId);
4340
4341 msg.append(", priority=");
4342 msg.append(priority);
4343
4344 msg.append(StringPool.CLOSE_CURLY_BRACE);
4345
4346 throw new NoSuchThreadException(msg.toString());
4347 }
4348 else {
4349 return list.get(0);
4350 }
4351 }
4352
4353
4368 public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
4369 double priority, OrderByComparator orderByComparator)
4370 throws NoSuchThreadException, SystemException {
4371 MBThread mbThread = findByPrimaryKey(threadId);
4372
4373 Session session = null;
4374
4375 try {
4376 session = openSession();
4377
4378 MBThread[] array = new MBThreadImpl[3];
4379
4380 array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
4381 priority, orderByComparator, true);
4382
4383 array[1] = mbThread;
4384
4385 array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
4386 priority, orderByComparator, false);
4387
4388 return array;
4389 }
4390 catch (Exception e) {
4391 throw processException(e);
4392 }
4393 finally {
4394 closeSession(session);
4395 }
4396 }
4397
4398 protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
4399 long categoryId, double priority, OrderByComparator orderByComparator,
4400 boolean previous) {
4401 StringBundler query = null;
4402
4403 if (orderByComparator != null) {
4404 query = new StringBundler(6 +
4405 (orderByComparator.getOrderByFields().length * 6));
4406 }
4407 else {
4408 query = new StringBundler(3);
4409 }
4410
4411 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4412
4413 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4414
4415 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4416
4417 if (orderByComparator != null) {
4418 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4419
4420 if (orderByConditionFields.length > 0) {
4421 query.append(WHERE_AND);
4422 }
4423
4424 for (int i = 0; i < orderByConditionFields.length; i++) {
4425 query.append(_ORDER_BY_ENTITY_ALIAS);
4426 query.append(orderByConditionFields[i]);
4427
4428 if ((i + 1) < orderByConditionFields.length) {
4429 if (orderByComparator.isAscending() ^ previous) {
4430 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4431 }
4432 else {
4433 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4434 }
4435 }
4436 else {
4437 if (orderByComparator.isAscending() ^ previous) {
4438 query.append(WHERE_GREATER_THAN);
4439 }
4440 else {
4441 query.append(WHERE_LESSER_THAN);
4442 }
4443 }
4444 }
4445
4446 query.append(ORDER_BY_CLAUSE);
4447
4448 String[] orderByFields = orderByComparator.getOrderByFields();
4449
4450 for (int i = 0; i < orderByFields.length; i++) {
4451 query.append(_ORDER_BY_ENTITY_ALIAS);
4452 query.append(orderByFields[i]);
4453
4454 if ((i + 1) < orderByFields.length) {
4455 if (orderByComparator.isAscending() ^ previous) {
4456 query.append(ORDER_BY_ASC_HAS_NEXT);
4457 }
4458 else {
4459 query.append(ORDER_BY_DESC_HAS_NEXT);
4460 }
4461 }
4462 else {
4463 if (orderByComparator.isAscending() ^ previous) {
4464 query.append(ORDER_BY_ASC);
4465 }
4466 else {
4467 query.append(ORDER_BY_DESC);
4468 }
4469 }
4470 }
4471 }
4472
4473 else {
4474 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4475 }
4476
4477 String sql = query.toString();
4478
4479 Query q = session.createQuery(sql);
4480
4481 q.setFirstResult(0);
4482 q.setMaxResults(2);
4483
4484 QueryPos qPos = QueryPos.getInstance(q);
4485
4486 qPos.add(categoryId);
4487
4488 qPos.add(priority);
4489
4490 if (orderByComparator != null) {
4491 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4492
4493 for (Object value : values) {
4494 qPos.add(value);
4495 }
4496 }
4497
4498 List<MBThread> list = q.list();
4499
4500 if (list.size() == 2) {
4501 return list.get(1);
4502 }
4503 else {
4504 return null;
4505 }
4506 }
4507
4508
4516 public List<MBThread> findByL_P(Date lastPostDate, double priority)
4517 throws SystemException {
4518 return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
4519 QueryUtil.ALL_POS, null);
4520 }
4521
4522
4536 public List<MBThread> findByL_P(Date lastPostDate, double priority,
4537 int start, int end) throws SystemException {
4538 return findByL_P(lastPostDate, priority, start, end, null);
4539 }
4540
4541
4556 public List<MBThread> findByL_P(Date lastPostDate, double priority,
4557 int start, int end, OrderByComparator orderByComparator)
4558 throws SystemException {
4559 FinderPath finderPath = null;
4560 Object[] finderArgs = null;
4561
4562 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4563 (orderByComparator == null)) {
4564 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
4565 finderArgs = new Object[] { lastPostDate, priority };
4566 }
4567 else {
4568 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
4569 finderArgs = new Object[] {
4570 lastPostDate, priority,
4571
4572 start, end, orderByComparator
4573 };
4574 }
4575
4576 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4577 finderArgs, this);
4578
4579 if ((list != null) && !list.isEmpty()) {
4580 for (MBThread mbThread : list) {
4581 if (!Validator.equals(lastPostDate, mbThread.getLastPostDate()) ||
4582 (priority != mbThread.getPriority())) {
4583 list = null;
4584
4585 break;
4586 }
4587 }
4588 }
4589
4590 if (list == null) {
4591 StringBundler query = null;
4592
4593 if (orderByComparator != null) {
4594 query = new StringBundler(4 +
4595 (orderByComparator.getOrderByFields().length * 3));
4596 }
4597 else {
4598 query = new StringBundler(4);
4599 }
4600
4601 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4602
4603 if (lastPostDate == null) {
4604 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
4605 }
4606 else {
4607 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
4608 }
4609
4610 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
4611
4612 if (orderByComparator != null) {
4613 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4614 orderByComparator);
4615 }
4616
4617 else {
4618 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4619 }
4620
4621 String sql = query.toString();
4622
4623 Session session = null;
4624
4625 try {
4626 session = openSession();
4627
4628 Query q = session.createQuery(sql);
4629
4630 QueryPos qPos = QueryPos.getInstance(q);
4631
4632 if (lastPostDate != null) {
4633 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4634 }
4635
4636 qPos.add(priority);
4637
4638 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
4639 end);
4640 }
4641 catch (Exception e) {
4642 throw processException(e);
4643 }
4644 finally {
4645 if (list == null) {
4646 FinderCacheUtil.removeResult(finderPath, finderArgs);
4647 }
4648 else {
4649 cacheResult(list);
4650
4651 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4652 }
4653
4654 closeSession(session);
4655 }
4656 }
4657
4658 return list;
4659 }
4660
4661
4675 public MBThread findByL_P_First(Date lastPostDate, double priority,
4676 OrderByComparator orderByComparator)
4677 throws NoSuchThreadException, SystemException {
4678 List<MBThread> list = findByL_P(lastPostDate, priority, 0, 1,
4679 orderByComparator);
4680
4681 if (list.isEmpty()) {
4682 StringBundler msg = new StringBundler(6);
4683
4684 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4685
4686 msg.append("lastPostDate=");
4687 msg.append(lastPostDate);
4688
4689 msg.append(", priority=");
4690 msg.append(priority);
4691
4692 msg.append(StringPool.CLOSE_CURLY_BRACE);
4693
4694 throw new NoSuchThreadException(msg.toString());
4695 }
4696 else {
4697 return list.get(0);
4698 }
4699 }
4700
4701
4715 public MBThread findByL_P_Last(Date lastPostDate, double priority,
4716 OrderByComparator orderByComparator)
4717 throws NoSuchThreadException, SystemException {
4718 int count = countByL_P(lastPostDate, priority);
4719
4720 List<MBThread> list = findByL_P(lastPostDate, priority, count - 1,
4721 count, orderByComparator);
4722
4723 if (list.isEmpty()) {
4724 StringBundler msg = new StringBundler(6);
4725
4726 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4727
4728 msg.append("lastPostDate=");
4729 msg.append(lastPostDate);
4730
4731 msg.append(", priority=");
4732 msg.append(priority);
4733
4734 msg.append(StringPool.CLOSE_CURLY_BRACE);
4735
4736 throw new NoSuchThreadException(msg.toString());
4737 }
4738 else {
4739 return list.get(0);
4740 }
4741 }
4742
4743
4758 public MBThread[] findByL_P_PrevAndNext(long threadId, Date lastPostDate,
4759 double priority, OrderByComparator orderByComparator)
4760 throws NoSuchThreadException, SystemException {
4761 MBThread mbThread = findByPrimaryKey(threadId);
4762
4763 Session session = null;
4764
4765 try {
4766 session = openSession();
4767
4768 MBThread[] array = new MBThreadImpl[3];
4769
4770 array[0] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
4771 priority, orderByComparator, true);
4772
4773 array[1] = mbThread;
4774
4775 array[2] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
4776 priority, orderByComparator, false);
4777
4778 return array;
4779 }
4780 catch (Exception e) {
4781 throw processException(e);
4782 }
4783 finally {
4784 closeSession(session);
4785 }
4786 }
4787
4788 protected MBThread getByL_P_PrevAndNext(Session session, MBThread mbThread,
4789 Date lastPostDate, double priority,
4790 OrderByComparator orderByComparator, boolean previous) {
4791 StringBundler query = null;
4792
4793 if (orderByComparator != null) {
4794 query = new StringBundler(6 +
4795 (orderByComparator.getOrderByFields().length * 6));
4796 }
4797 else {
4798 query = new StringBundler(3);
4799 }
4800
4801 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4802
4803 if (lastPostDate == null) {
4804 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
4805 }
4806 else {
4807 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
4808 }
4809
4810 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
4811
4812 if (orderByComparator != null) {
4813 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4814
4815 if (orderByConditionFields.length > 0) {
4816 query.append(WHERE_AND);
4817 }
4818
4819 for (int i = 0; i < orderByConditionFields.length; i++) {
4820 query.append(_ORDER_BY_ENTITY_ALIAS);
4821 query.append(orderByConditionFields[i]);
4822
4823 if ((i + 1) < orderByConditionFields.length) {
4824 if (orderByComparator.isAscending() ^ previous) {
4825 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4826 }
4827 else {
4828 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4829 }
4830 }
4831 else {
4832 if (orderByComparator.isAscending() ^ previous) {
4833 query.append(WHERE_GREATER_THAN);
4834 }
4835 else {
4836 query.append(WHERE_LESSER_THAN);
4837 }
4838 }
4839 }
4840
4841 query.append(ORDER_BY_CLAUSE);
4842
4843 String[] orderByFields = orderByComparator.getOrderByFields();
4844
4845 for (int i = 0; i < orderByFields.length; i++) {
4846 query.append(_ORDER_BY_ENTITY_ALIAS);
4847 query.append(orderByFields[i]);
4848
4849 if ((i + 1) < orderByFields.length) {
4850 if (orderByComparator.isAscending() ^ previous) {
4851 query.append(ORDER_BY_ASC_HAS_NEXT);
4852 }
4853 else {
4854 query.append(ORDER_BY_DESC_HAS_NEXT);
4855 }
4856 }
4857 else {
4858 if (orderByComparator.isAscending() ^ previous) {
4859 query.append(ORDER_BY_ASC);
4860 }
4861 else {
4862 query.append(ORDER_BY_DESC);
4863 }
4864 }
4865 }
4866 }
4867
4868 else {
4869 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4870 }
4871
4872 String sql = query.toString();
4873
4874 Query q = session.createQuery(sql);
4875
4876 q.setFirstResult(0);
4877 q.setMaxResults(2);
4878
4879 QueryPos qPos = QueryPos.getInstance(q);
4880
4881 if (lastPostDate != null) {
4882 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4883 }
4884
4885 qPos.add(priority);
4886
4887 if (orderByComparator != null) {
4888 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4889
4890 for (Object value : values) {
4891 qPos.add(value);
4892 }
4893 }
4894
4895 List<MBThread> list = q.list();
4896
4897 if (list.size() == 2) {
4898 return list.get(1);
4899 }
4900 else {
4901 return null;
4902 }
4903 }
4904
4905
4914 public List<MBThread> findByG_C_L(long groupId, long categoryId,
4915 Date lastPostDate) throws SystemException {
4916 return findByG_C_L(groupId, categoryId, lastPostDate,
4917 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4918 }
4919
4920
4935 public List<MBThread> findByG_C_L(long groupId, long categoryId,
4936 Date lastPostDate, int start, int end) throws SystemException {
4937 return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
4938 }
4939
4940
4956 public List<MBThread> findByG_C_L(long groupId, long categoryId,
4957 Date lastPostDate, int start, int end,
4958 OrderByComparator orderByComparator) throws SystemException {
4959 FinderPath finderPath = null;
4960 Object[] finderArgs = null;
4961
4962 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4963 (orderByComparator == null)) {
4964 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
4965 finderArgs = new Object[] { groupId, categoryId, lastPostDate };
4966 }
4967 else {
4968 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
4969 finderArgs = new Object[] {
4970 groupId, categoryId, lastPostDate,
4971
4972 start, end, orderByComparator
4973 };
4974 }
4975
4976 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4977 finderArgs, this);
4978
4979 if ((list != null) && !list.isEmpty()) {
4980 for (MBThread mbThread : list) {
4981 if ((groupId != mbThread.getGroupId()) ||
4982 (categoryId != mbThread.getCategoryId()) ||
4983 !Validator.equals(lastPostDate,
4984 mbThread.getLastPostDate())) {
4985 list = null;
4986
4987 break;
4988 }
4989 }
4990 }
4991
4992 if (list == null) {
4993 StringBundler query = null;
4994
4995 if (orderByComparator != null) {
4996 query = new StringBundler(5 +
4997 (orderByComparator.getOrderByFields().length * 3));
4998 }
4999 else {
5000 query = new StringBundler(5);
5001 }
5002
5003 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5004
5005 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5006
5007 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5008
5009 if (lastPostDate == null) {
5010 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5011 }
5012 else {
5013 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5014 }
5015
5016 if (orderByComparator != null) {
5017 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5018 orderByComparator);
5019 }
5020
5021 else {
5022 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5023 }
5024
5025 String sql = query.toString();
5026
5027 Session session = null;
5028
5029 try {
5030 session = openSession();
5031
5032 Query q = session.createQuery(sql);
5033
5034 QueryPos qPos = QueryPos.getInstance(q);
5035
5036 qPos.add(groupId);
5037
5038 qPos.add(categoryId);
5039
5040 if (lastPostDate != null) {
5041 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5042 }
5043
5044 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
5045 end);
5046 }
5047 catch (Exception e) {
5048 throw processException(e);
5049 }
5050 finally {
5051 if (list == null) {
5052 FinderCacheUtil.removeResult(finderPath, finderArgs);
5053 }
5054 else {
5055 cacheResult(list);
5056
5057 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5058 }
5059
5060 closeSession(session);
5061 }
5062 }
5063
5064 return list;
5065 }
5066
5067
5082 public MBThread findByG_C_L_First(long groupId, long categoryId,
5083 Date lastPostDate, OrderByComparator orderByComparator)
5084 throws NoSuchThreadException, SystemException {
5085 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
5086 1, orderByComparator);
5087
5088 if (list.isEmpty()) {
5089 StringBundler msg = new StringBundler(8);
5090
5091 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5092
5093 msg.append("groupId=");
5094 msg.append(groupId);
5095
5096 msg.append(", categoryId=");
5097 msg.append(categoryId);
5098
5099 msg.append(", lastPostDate=");
5100 msg.append(lastPostDate);
5101
5102 msg.append(StringPool.CLOSE_CURLY_BRACE);
5103
5104 throw new NoSuchThreadException(msg.toString());
5105 }
5106 else {
5107 return list.get(0);
5108 }
5109 }
5110
5111
5126 public MBThread findByG_C_L_Last(long groupId, long categoryId,
5127 Date lastPostDate, OrderByComparator orderByComparator)
5128 throws NoSuchThreadException, SystemException {
5129 int count = countByG_C_L(groupId, categoryId, lastPostDate);
5130
5131 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
5132 count - 1, count, orderByComparator);
5133
5134 if (list.isEmpty()) {
5135 StringBundler msg = new StringBundler(8);
5136
5137 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5138
5139 msg.append("groupId=");
5140 msg.append(groupId);
5141
5142 msg.append(", categoryId=");
5143 msg.append(categoryId);
5144
5145 msg.append(", lastPostDate=");
5146 msg.append(lastPostDate);
5147
5148 msg.append(StringPool.CLOSE_CURLY_BRACE);
5149
5150 throw new NoSuchThreadException(msg.toString());
5151 }
5152 else {
5153 return list.get(0);
5154 }
5155 }
5156
5157
5173 public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
5174 long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
5175 throws NoSuchThreadException, SystemException {
5176 MBThread mbThread = findByPrimaryKey(threadId);
5177
5178 Session session = null;
5179
5180 try {
5181 session = openSession();
5182
5183 MBThread[] array = new MBThreadImpl[3];
5184
5185 array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
5186 categoryId, lastPostDate, orderByComparator, true);
5187
5188 array[1] = mbThread;
5189
5190 array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
5191 categoryId, lastPostDate, orderByComparator, false);
5192
5193 return array;
5194 }
5195 catch (Exception e) {
5196 throw processException(e);
5197 }
5198 finally {
5199 closeSession(session);
5200 }
5201 }
5202
5203 protected MBThread getByG_C_L_PrevAndNext(Session session,
5204 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
5205 OrderByComparator orderByComparator, boolean previous) {
5206 StringBundler query = null;
5207
5208 if (orderByComparator != null) {
5209 query = new StringBundler(6 +
5210 (orderByComparator.getOrderByFields().length * 6));
5211 }
5212 else {
5213 query = new StringBundler(3);
5214 }
5215
5216 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5217
5218 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5219
5220 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5221
5222 if (lastPostDate == null) {
5223 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5224 }
5225 else {
5226 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5227 }
5228
5229 if (orderByComparator != null) {
5230 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5231
5232 if (orderByConditionFields.length > 0) {
5233 query.append(WHERE_AND);
5234 }
5235
5236 for (int i = 0; i < orderByConditionFields.length; i++) {
5237 query.append(_ORDER_BY_ENTITY_ALIAS);
5238 query.append(orderByConditionFields[i]);
5239
5240 if ((i + 1) < orderByConditionFields.length) {
5241 if (orderByComparator.isAscending() ^ previous) {
5242 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5243 }
5244 else {
5245 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5246 }
5247 }
5248 else {
5249 if (orderByComparator.isAscending() ^ previous) {
5250 query.append(WHERE_GREATER_THAN);
5251 }
5252 else {
5253 query.append(WHERE_LESSER_THAN);
5254 }
5255 }
5256 }
5257
5258 query.append(ORDER_BY_CLAUSE);
5259
5260 String[] orderByFields = orderByComparator.getOrderByFields();
5261
5262 for (int i = 0; i < orderByFields.length; i++) {
5263 query.append(_ORDER_BY_ENTITY_ALIAS);
5264 query.append(orderByFields[i]);
5265
5266 if ((i + 1) < orderByFields.length) {
5267 if (orderByComparator.isAscending() ^ previous) {
5268 query.append(ORDER_BY_ASC_HAS_NEXT);
5269 }
5270 else {
5271 query.append(ORDER_BY_DESC_HAS_NEXT);
5272 }
5273 }
5274 else {
5275 if (orderByComparator.isAscending() ^ previous) {
5276 query.append(ORDER_BY_ASC);
5277 }
5278 else {
5279 query.append(ORDER_BY_DESC);
5280 }
5281 }
5282 }
5283 }
5284
5285 else {
5286 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5287 }
5288
5289 String sql = query.toString();
5290
5291 Query q = session.createQuery(sql);
5292
5293 q.setFirstResult(0);
5294 q.setMaxResults(2);
5295
5296 QueryPos qPos = QueryPos.getInstance(q);
5297
5298 qPos.add(groupId);
5299
5300 qPos.add(categoryId);
5301
5302 if (lastPostDate != null) {
5303 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5304 }
5305
5306 if (orderByComparator != null) {
5307 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5308
5309 for (Object value : values) {
5310 qPos.add(value);
5311 }
5312 }
5313
5314 List<MBThread> list = q.list();
5315
5316 if (list.size() == 2) {
5317 return list.get(1);
5318 }
5319 else {
5320 return null;
5321 }
5322 }
5323
5324
5333 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5334 Date lastPostDate) throws SystemException {
5335 return filterFindByG_C_L(groupId, categoryId, lastPostDate,
5336 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5337 }
5338
5339
5354 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5355 Date lastPostDate, int start, int end) throws SystemException {
5356 return filterFindByG_C_L(groupId, categoryId, lastPostDate, start, end,
5357 null);
5358 }
5359
5360
5376 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5377 Date lastPostDate, int start, int end,
5378 OrderByComparator orderByComparator) throws SystemException {
5379 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5380 return findByG_C_L(groupId, categoryId, lastPostDate, start, end,
5381 orderByComparator);
5382 }
5383
5384 StringBundler query = null;
5385
5386 if (orderByComparator != null) {
5387 query = new StringBundler(5 +
5388 (orderByComparator.getOrderByFields().length * 3));
5389 }
5390 else {
5391 query = new StringBundler(5);
5392 }
5393
5394 if (getDB().isSupportsInlineDistinct()) {
5395 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5396 }
5397 else {
5398 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5399 }
5400
5401 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5402
5403 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5404
5405 if (lastPostDate == null) {
5406 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5407 }
5408 else {
5409 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5410 }
5411
5412 if (!getDB().isSupportsInlineDistinct()) {
5413 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5414 }
5415
5416 if (orderByComparator != null) {
5417 if (getDB().isSupportsInlineDistinct()) {
5418 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5419 orderByComparator);
5420 }
5421 else {
5422 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5423 orderByComparator);
5424 }
5425 }
5426
5427 else {
5428 if (getDB().isSupportsInlineDistinct()) {
5429 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5430 }
5431 else {
5432 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5433 }
5434 }
5435
5436 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5437 MBThread.class.getName(),
5438 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5439
5440 Session session = null;
5441
5442 try {
5443 session = openSession();
5444
5445 SQLQuery q = session.createSQLQuery(sql);
5446
5447 if (getDB().isSupportsInlineDistinct()) {
5448 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5449 }
5450 else {
5451 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5452 }
5453
5454 QueryPos qPos = QueryPos.getInstance(q);
5455
5456 qPos.add(groupId);
5457
5458 qPos.add(categoryId);
5459
5460 if (lastPostDate != null) {
5461 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5462 }
5463
5464 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5465 }
5466 catch (Exception e) {
5467 throw processException(e);
5468 }
5469 finally {
5470 closeSession(session);
5471 }
5472 }
5473
5474
5486 public MBThread[] filterFindByG_C_L_PrevAndNext(long threadId,
5487 long groupId, long categoryId, Date lastPostDate,
5488 OrderByComparator orderByComparator)
5489 throws NoSuchThreadException, SystemException {
5490 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5491 return findByG_C_L_PrevAndNext(threadId, groupId, categoryId,
5492 lastPostDate, orderByComparator);
5493 }
5494
5495 MBThread mbThread = findByPrimaryKey(threadId);
5496
5497 Session session = null;
5498
5499 try {
5500 session = openSession();
5501
5502 MBThread[] array = new MBThreadImpl[3];
5503
5504 array[0] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
5505 categoryId, lastPostDate, orderByComparator, true);
5506
5507 array[1] = mbThread;
5508
5509 array[2] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
5510 categoryId, lastPostDate, orderByComparator, false);
5511
5512 return array;
5513 }
5514 catch (Exception e) {
5515 throw processException(e);
5516 }
5517 finally {
5518 closeSession(session);
5519 }
5520 }
5521
5522 protected MBThread filterGetByG_C_L_PrevAndNext(Session session,
5523 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
5524 OrderByComparator orderByComparator, boolean previous) {
5525 StringBundler query = null;
5526
5527 if (orderByComparator != null) {
5528 query = new StringBundler(6 +
5529 (orderByComparator.getOrderByFields().length * 6));
5530 }
5531 else {
5532 query = new StringBundler(3);
5533 }
5534
5535 if (getDB().isSupportsInlineDistinct()) {
5536 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5537 }
5538 else {
5539 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5540 }
5541
5542 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5543
5544 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5545
5546 if (lastPostDate == null) {
5547 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5548 }
5549 else {
5550 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5551 }
5552
5553 if (!getDB().isSupportsInlineDistinct()) {
5554 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5555 }
5556
5557 if (orderByComparator != null) {
5558 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5559
5560 if (orderByConditionFields.length > 0) {
5561 query.append(WHERE_AND);
5562 }
5563
5564 for (int i = 0; i < orderByConditionFields.length; i++) {
5565 if (getDB().isSupportsInlineDistinct()) {
5566 query.append(_ORDER_BY_ENTITY_ALIAS);
5567 }
5568 else {
5569 query.append(_ORDER_BY_ENTITY_TABLE);
5570 }
5571
5572 query.append(orderByConditionFields[i]);
5573
5574 if ((i + 1) < orderByConditionFields.length) {
5575 if (orderByComparator.isAscending() ^ previous) {
5576 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5577 }
5578 else {
5579 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5580 }
5581 }
5582 else {
5583 if (orderByComparator.isAscending() ^ previous) {
5584 query.append(WHERE_GREATER_THAN);
5585 }
5586 else {
5587 query.append(WHERE_LESSER_THAN);
5588 }
5589 }
5590 }
5591
5592 query.append(ORDER_BY_CLAUSE);
5593
5594 String[] orderByFields = orderByComparator.getOrderByFields();
5595
5596 for (int i = 0; i < orderByFields.length; i++) {
5597 if (getDB().isSupportsInlineDistinct()) {
5598 query.append(_ORDER_BY_ENTITY_ALIAS);
5599 }
5600 else {
5601 query.append(_ORDER_BY_ENTITY_TABLE);
5602 }
5603
5604 query.append(orderByFields[i]);
5605
5606 if ((i + 1) < orderByFields.length) {
5607 if (orderByComparator.isAscending() ^ previous) {
5608 query.append(ORDER_BY_ASC_HAS_NEXT);
5609 }
5610 else {
5611 query.append(ORDER_BY_DESC_HAS_NEXT);
5612 }
5613 }
5614 else {
5615 if (orderByComparator.isAscending() ^ previous) {
5616 query.append(ORDER_BY_ASC);
5617 }
5618 else {
5619 query.append(ORDER_BY_DESC);
5620 }
5621 }
5622 }
5623 }
5624
5625 else {
5626 if (getDB().isSupportsInlineDistinct()) {
5627 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5628 }
5629 else {
5630 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5631 }
5632 }
5633
5634 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5635 MBThread.class.getName(),
5636 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5637
5638 SQLQuery q = session.createSQLQuery(sql);
5639
5640 q.setFirstResult(0);
5641 q.setMaxResults(2);
5642
5643 if (getDB().isSupportsInlineDistinct()) {
5644 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5645 }
5646 else {
5647 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5648 }
5649
5650 QueryPos qPos = QueryPos.getInstance(q);
5651
5652 qPos.add(groupId);
5653
5654 qPos.add(categoryId);
5655
5656 if (lastPostDate != null) {
5657 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5658 }
5659
5660 if (orderByComparator != null) {
5661 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5662
5663 for (Object value : values) {
5664 qPos.add(value);
5665 }
5666 }
5667
5668 List<MBThread> list = q.list();
5669
5670 if (list.size() == 2) {
5671 return list.get(1);
5672 }
5673 else {
5674 return null;
5675 }
5676 }
5677
5678
5687 public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
5688 throws SystemException {
5689 return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
5690 QueryUtil.ALL_POS, null);
5691 }
5692
5693
5708 public List<MBThread> findByG_C_S(long groupId, long categoryId,
5709 int status, int start, int end) throws SystemException {
5710 return findByG_C_S(groupId, categoryId, status, start, end, null);
5711 }
5712
5713
5729 public List<MBThread> findByG_C_S(long groupId, long categoryId,
5730 int status, int start, int end, OrderByComparator orderByComparator)
5731 throws SystemException {
5732 FinderPath finderPath = null;
5733 Object[] finderArgs = null;
5734
5735 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5736 (orderByComparator == null)) {
5737 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
5738 finderArgs = new Object[] { groupId, categoryId, status };
5739 }
5740 else {
5741 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
5742 finderArgs = new Object[] {
5743 groupId, categoryId, status,
5744
5745 start, end, orderByComparator
5746 };
5747 }
5748
5749 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5750 finderArgs, this);
5751
5752 if ((list != null) && !list.isEmpty()) {
5753 for (MBThread mbThread : list) {
5754 if ((groupId != mbThread.getGroupId()) ||
5755 (categoryId != mbThread.getCategoryId()) ||
5756 (status != mbThread.getStatus())) {
5757 list = null;
5758
5759 break;
5760 }
5761 }
5762 }
5763
5764 if (list == null) {
5765 StringBundler query = null;
5766
5767 if (orderByComparator != null) {
5768 query = new StringBundler(5 +
5769 (orderByComparator.getOrderByFields().length * 3));
5770 }
5771 else {
5772 query = new StringBundler(5);
5773 }
5774
5775 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5776
5777 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
5778
5779 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
5780
5781 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
5782
5783 if (orderByComparator != null) {
5784 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5785 orderByComparator);
5786 }
5787
5788 else {
5789 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5790 }
5791
5792 String sql = query.toString();
5793
5794 Session session = null;
5795
5796 try {
5797 session = openSession();
5798
5799 Query q = session.createQuery(sql);
5800
5801 QueryPos qPos = QueryPos.getInstance(q);
5802
5803 qPos.add(groupId);
5804
5805 qPos.add(categoryId);
5806
5807 qPos.add(status);
5808
5809 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
5810 end);
5811 }
5812 catch (Exception e) {
5813 throw processException(e);
5814 }
5815 finally {
5816 if (list == null) {
5817 FinderCacheUtil.removeResult(finderPath, finderArgs);
5818 }
5819 else {
5820 cacheResult(list);
5821
5822 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5823 }
5824
5825 closeSession(session);
5826 }
5827 }
5828
5829 return list;
5830 }
5831
5832
5847 public MBThread findByG_C_S_First(long groupId, long categoryId,
5848 int status, OrderByComparator orderByComparator)
5849 throws NoSuchThreadException, SystemException {
5850 List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
5851 orderByComparator);
5852
5853 if (list.isEmpty()) {
5854 StringBundler msg = new StringBundler(8);
5855
5856 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5857
5858 msg.append("groupId=");
5859 msg.append(groupId);
5860
5861 msg.append(", categoryId=");
5862 msg.append(categoryId);
5863
5864 msg.append(", status=");
5865 msg.append(status);
5866
5867 msg.append(StringPool.CLOSE_CURLY_BRACE);
5868
5869 throw new NoSuchThreadException(msg.toString());
5870 }
5871 else {
5872 return list.get(0);
5873 }
5874 }
5875
5876
5891 public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
5892 OrderByComparator orderByComparator)
5893 throws NoSuchThreadException, SystemException {
5894 int count = countByG_C_S(groupId, categoryId, status);
5895
5896 List<MBThread> list = findByG_C_S(groupId, categoryId, status,
5897 count - 1, count, orderByComparator);
5898
5899 if (list.isEmpty()) {
5900 StringBundler msg = new StringBundler(8);
5901
5902 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5903
5904 msg.append("groupId=");
5905 msg.append(groupId);
5906
5907 msg.append(", categoryId=");
5908 msg.append(categoryId);
5909
5910 msg.append(", status=");
5911 msg.append(status);
5912
5913 msg.append(StringPool.CLOSE_CURLY_BRACE);
5914
5915 throw new NoSuchThreadException(msg.toString());
5916 }
5917 else {
5918 return list.get(0);
5919 }
5920 }
5921
5922
5938 public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
5939 long categoryId, int status, OrderByComparator orderByComparator)
5940 throws NoSuchThreadException, SystemException {
5941 MBThread mbThread = findByPrimaryKey(threadId);
5942
5943 Session session = null;
5944
5945 try {
5946 session = openSession();
5947
5948 MBThread[] array = new MBThreadImpl[3];
5949
5950 array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
5951 categoryId, status, orderByComparator, true);
5952
5953 array[1] = mbThread;
5954
5955 array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
5956 categoryId, status, orderByComparator, false);
5957
5958 return array;
5959 }
5960 catch (Exception e) {
5961 throw processException(e);
5962 }
5963 finally {
5964 closeSession(session);
5965 }
5966 }
5967
5968 protected MBThread getByG_C_S_PrevAndNext(Session session,
5969 MBThread mbThread, long groupId, long categoryId, int status,
5970 OrderByComparator orderByComparator, boolean previous) {
5971 StringBundler query = null;
5972
5973 if (orderByComparator != null) {
5974 query = new StringBundler(6 +
5975 (orderByComparator.getOrderByFields().length * 6));
5976 }
5977 else {
5978 query = new StringBundler(3);
5979 }
5980
5981 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5982
5983 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
5984
5985 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
5986
5987 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
5988
5989 if (orderByComparator != null) {
5990 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5991
5992 if (orderByConditionFields.length > 0) {
5993 query.append(WHERE_AND);
5994 }
5995
5996 for (int i = 0; i < orderByConditionFields.length; i++) {
5997 query.append(_ORDER_BY_ENTITY_ALIAS);
5998 query.append(orderByConditionFields[i]);
5999
6000 if ((i + 1) < orderByConditionFields.length) {
6001 if (orderByComparator.isAscending() ^ previous) {
6002 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6003 }
6004 else {
6005 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6006 }
6007 }
6008 else {
6009 if (orderByComparator.isAscending() ^ previous) {
6010 query.append(WHERE_GREATER_THAN);
6011 }
6012 else {
6013 query.append(WHERE_LESSER_THAN);
6014 }
6015 }
6016 }
6017
6018 query.append(ORDER_BY_CLAUSE);
6019
6020 String[] orderByFields = orderByComparator.getOrderByFields();
6021
6022 for (int i = 0; i < orderByFields.length; i++) {
6023 query.append(_ORDER_BY_ENTITY_ALIAS);
6024 query.append(orderByFields[i]);
6025
6026 if ((i + 1) < orderByFields.length) {
6027 if (orderByComparator.isAscending() ^ previous) {
6028 query.append(ORDER_BY_ASC_HAS_NEXT);
6029 }
6030 else {
6031 query.append(ORDER_BY_DESC_HAS_NEXT);
6032 }
6033 }
6034 else {
6035 if (orderByComparator.isAscending() ^ previous) {
6036 query.append(ORDER_BY_ASC);
6037 }
6038 else {
6039 query.append(ORDER_BY_DESC);
6040 }
6041 }
6042 }
6043 }
6044
6045 else {
6046 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6047 }
6048
6049 String sql = query.toString();
6050
6051 Query q = session.createQuery(sql);
6052
6053 q.setFirstResult(0);
6054 q.setMaxResults(2);
6055
6056 QueryPos qPos = QueryPos.getInstance(q);
6057
6058 qPos.add(groupId);
6059
6060 qPos.add(categoryId);
6061
6062 qPos.add(status);
6063
6064 if (orderByComparator != null) {
6065 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6066
6067 for (Object value : values) {
6068 qPos.add(value);
6069 }
6070 }
6071
6072 List<MBThread> list = q.list();
6073
6074 if (list.size() == 2) {
6075 return list.get(1);
6076 }
6077 else {
6078 return null;
6079 }
6080 }
6081
6082
6095 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
6096 int status) throws SystemException {
6097 return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
6098 QueryUtil.ALL_POS, null);
6099 }
6100
6101
6116 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
6117 int status, int start, int end) throws SystemException {
6118 return findByG_C_S(groupId, categoryIds, status, start, end, null);
6119 }
6120
6121
6137 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
6138 int status, int start, int end, OrderByComparator orderByComparator)
6139 throws SystemException {
6140 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
6141 Object[] finderArgs = null;
6142
6143 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6144 (orderByComparator == null)) {
6145 finderArgs = new Object[] {
6146 groupId, StringUtil.merge(categoryIds), status
6147 };
6148 }
6149 else {
6150 finderArgs = new Object[] {
6151 groupId, StringUtil.merge(categoryIds), status,
6152
6153 start, end, orderByComparator
6154 };
6155 }
6156
6157 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6158 finderArgs, this);
6159
6160 if ((list != null) && !list.isEmpty()) {
6161 for (MBThread mbThread : list) {
6162 if ((groupId != mbThread.getGroupId()) ||
6163 !ArrayUtil.contains(categoryIds,
6164 mbThread.getCategoryId()) ||
6165 (status != mbThread.getStatus())) {
6166 list = null;
6167
6168 break;
6169 }
6170 }
6171 }
6172
6173 if (list == null) {
6174 StringBundler query = new StringBundler();
6175
6176 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6177
6178 boolean conjunctionable = false;
6179
6180 if (conjunctionable) {
6181 query.append(WHERE_AND);
6182 }
6183
6184 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
6185
6186 conjunctionable = true;
6187
6188 if ((categoryIds == null) || (categoryIds.length > 0)) {
6189 if (conjunctionable) {
6190 query.append(WHERE_AND);
6191 }
6192
6193 query.append(StringPool.OPEN_PARENTHESIS);
6194
6195 for (int i = 0; i < categoryIds.length; i++) {
6196 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
6197
6198 if ((i + 1) < categoryIds.length) {
6199 query.append(WHERE_OR);
6200 }
6201 }
6202
6203 query.append(StringPool.CLOSE_PARENTHESIS);
6204
6205 conjunctionable = true;
6206 }
6207
6208 if (conjunctionable) {
6209 query.append(WHERE_AND);
6210 }
6211
6212 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
6213
6214 conjunctionable = true;
6215
6216 if (orderByComparator != null) {
6217 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6218 orderByComparator);
6219 }
6220
6221 else {
6222 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6223 }
6224
6225 String sql = query.toString();
6226
6227 Session session = null;
6228
6229 try {
6230 session = openSession();
6231
6232 Query q = session.createQuery(sql);
6233
6234 QueryPos qPos = QueryPos.getInstance(q);
6235
6236 qPos.add(groupId);
6237
6238 if (categoryIds != null) {
6239 qPos.add(categoryIds);
6240 }
6241
6242 qPos.add(status);
6243
6244 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
6245 end);
6246 }
6247 catch (Exception e) {
6248 throw processException(e);
6249 }
6250 finally {
6251 if (list == null) {
6252 FinderCacheUtil.removeResult(finderPath, finderArgs);
6253 }
6254 else {
6255 cacheResult(list);
6256
6257 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6258 }
6259
6260 closeSession(session);
6261 }
6262 }
6263
6264 return list;
6265 }
6266
6267
6276 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6277 int status) throws SystemException {
6278 return filterFindByG_C_S(groupId, categoryId, status,
6279 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6280 }
6281
6282
6297 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6298 int status, int start, int end) throws SystemException {
6299 return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
6300 }
6301
6302
6318 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6319 int status, int start, int end, OrderByComparator orderByComparator)
6320 throws SystemException {
6321 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6322 return findByG_C_S(groupId, categoryId, status, start, end,
6323 orderByComparator);
6324 }
6325
6326 StringBundler query = null;
6327
6328 if (orderByComparator != null) {
6329 query = new StringBundler(5 +
6330 (orderByComparator.getOrderByFields().length * 3));
6331 }
6332 else {
6333 query = new StringBundler(5);
6334 }
6335
6336 if (getDB().isSupportsInlineDistinct()) {
6337 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6338 }
6339 else {
6340 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6341 }
6342
6343 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6344
6345 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6346
6347 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6348
6349 if (!getDB().isSupportsInlineDistinct()) {
6350 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6351 }
6352
6353 if (orderByComparator != null) {
6354 if (getDB().isSupportsInlineDistinct()) {
6355 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6356 orderByComparator);
6357 }
6358 else {
6359 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6360 orderByComparator);
6361 }
6362 }
6363
6364 else {
6365 if (getDB().isSupportsInlineDistinct()) {
6366 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6367 }
6368 else {
6369 query.append(MBThreadModelImpl.ORDER_BY_SQL);
6370 }
6371 }
6372
6373 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6374 MBThread.class.getName(),
6375 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6376
6377 Session session = null;
6378
6379 try {
6380 session = openSession();
6381
6382 SQLQuery q = session.createSQLQuery(sql);
6383
6384 if (getDB().isSupportsInlineDistinct()) {
6385 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6386 }
6387 else {
6388 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6389 }
6390
6391 QueryPos qPos = QueryPos.getInstance(q);
6392
6393 qPos.add(groupId);
6394
6395 qPos.add(categoryId);
6396
6397 qPos.add(status);
6398
6399 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
6400 }
6401 catch (Exception e) {
6402 throw processException(e);
6403 }
6404 finally {
6405 closeSession(session);
6406 }
6407 }
6408
6409
6421 public MBThread[] filterFindByG_C_S_PrevAndNext(long threadId,
6422 long groupId, long categoryId, int status,
6423 OrderByComparator orderByComparator)
6424 throws NoSuchThreadException, SystemException {
6425 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6426 return findByG_C_S_PrevAndNext(threadId, groupId, categoryId,
6427 status, orderByComparator);
6428 }
6429
6430 MBThread mbThread = findByPrimaryKey(threadId);
6431
6432 Session session = null;
6433
6434 try {
6435 session = openSession();
6436
6437 MBThread[] array = new MBThreadImpl[3];
6438
6439 array[0] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
6440 categoryId, status, orderByComparator, true);
6441
6442 array[1] = mbThread;
6443
6444 array[2] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
6445 categoryId, status, orderByComparator, false);
6446
6447 return array;
6448 }
6449 catch (Exception e) {
6450 throw processException(e);
6451 }
6452 finally {
6453 closeSession(session);
6454 }
6455 }
6456
6457 protected MBThread filterGetByG_C_S_PrevAndNext(Session session,
6458 MBThread mbThread, long groupId, long categoryId, int status,
6459 OrderByComparator orderByComparator, boolean previous) {
6460 StringBundler query = null;
6461
6462 if (orderByComparator != null) {
6463 query = new StringBundler(6 +
6464 (orderByComparator.getOrderByFields().length * 6));
6465 }
6466 else {
6467 query = new StringBundler(3);
6468 }
6469
6470 if (getDB().isSupportsInlineDistinct()) {
6471 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6472 }
6473 else {
6474 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6475 }
6476
6477 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6478
6479 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6480
6481 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6482
6483 if (!getDB().isSupportsInlineDistinct()) {
6484 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6485 }
6486
6487 if (orderByComparator != null) {
6488 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6489
6490 if (orderByConditionFields.length > 0) {
6491 query.append(WHERE_AND);
6492 }
6493
6494 for (int i = 0; i < orderByConditionFields.length; i++) {
6495 if (getDB().isSupportsInlineDistinct()) {
6496 query.append(_ORDER_BY_ENTITY_ALIAS);
6497 }
6498 else {
6499 query.append(_ORDER_BY_ENTITY_TABLE);
6500 }
6501
6502 query.append(orderByConditionFields[i]);
6503
6504 if ((i + 1) < orderByConditionFields.length) {
6505 if (orderByComparator.isAscending() ^ previous) {
6506 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6507 }
6508 else {
6509 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6510 }
6511 }
6512 else {
6513 if (orderByComparator.isAscending() ^ previous) {
6514 query.append(WHERE_GREATER_THAN);
6515 }
6516 else {
6517 query.append(WHERE_LESSER_THAN);
6518 }
6519 }
6520 }
6521
6522 query.append(ORDER_BY_CLAUSE);
6523
6524 String[] orderByFields = orderByComparator.getOrderByFields();
6525
6526 for (int i = 0; i < orderByFields.length; i++) {
6527 if (getDB().isSupportsInlineDistinct()) {
6528 query.append(_ORDER_BY_ENTITY_ALIAS);
6529 }
6530 else {
6531 query.append(_ORDER_BY_ENTITY_TABLE);
6532 }
6533
6534 query.append(orderByFields[i]);
6535
6536 if ((i + 1) < orderByFields.length) {
6537 if (orderByComparator.isAscending() ^ previous) {
6538 query.append(ORDER_BY_ASC_HAS_NEXT);
6539 }
6540 else {
6541 query.append(ORDER_BY_DESC_HAS_NEXT);
6542 }
6543 }
6544 else {
6545 if (orderByComparator.isAscending() ^ previous) {
6546 query.append(ORDER_BY_ASC);
6547 }
6548 else {
6549 query.append(ORDER_BY_DESC);
6550 }
6551 }
6552 }
6553 }
6554
6555 else {
6556 if (getDB().isSupportsInlineDistinct()) {
6557 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6558 }
6559 else {
6560 query.append(MBThreadModelImpl.ORDER_BY_SQL);
6561 }
6562 }
6563
6564 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6565 MBThread.class.getName(),
6566 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6567
6568 SQLQuery q = session.createSQLQuery(sql);
6569
6570 q.setFirstResult(0);
6571 q.setMaxResults(2);
6572
6573 if (getDB().isSupportsInlineDistinct()) {
6574 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6575 }
6576 else {
6577 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6578 }
6579
6580 QueryPos qPos = QueryPos.getInstance(q);
6581
6582 qPos.add(groupId);
6583
6584 qPos.add(categoryId);
6585
6586 qPos.add(status);
6587
6588 if (orderByComparator != null) {
6589 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6590
6591 for (Object value : values) {
6592 qPos.add(value);
6593 }
6594 }
6595
6596 List<MBThread> list = q.list();
6597
6598 if (list.size() == 2) {
6599 return list.get(1);
6600 }
6601 else {
6602 return null;
6603 }
6604 }
6605
6606
6615 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6616 int status) throws SystemException {
6617 return filterFindByG_C_S(groupId, categoryIds, status,
6618 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6619 }
6620
6621
6636 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6637 int status, int start, int end) throws SystemException {
6638 return filterFindByG_C_S(groupId, categoryIds, status, start, end, null);
6639 }
6640
6641
6657 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6658 int status, int start, int end, OrderByComparator orderByComparator)
6659 throws SystemException {
6660 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6661 return findByG_C_S(groupId, categoryIds, status, start, end,
6662 orderByComparator);
6663 }
6664
6665 StringBundler query = new StringBundler();
6666
6667 if (getDB().isSupportsInlineDistinct()) {
6668 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6669 }
6670 else {
6671 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6672 }
6673
6674 boolean conjunctionable = false;
6675
6676 if (conjunctionable) {
6677 query.append(WHERE_AND);
6678 }
6679
6680 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
6681
6682 conjunctionable = true;
6683
6684 if ((categoryIds == null) || (categoryIds.length > 0)) {
6685 if (conjunctionable) {
6686 query.append(WHERE_AND);
6687 }
6688
6689 query.append(StringPool.OPEN_PARENTHESIS);
6690
6691 for (int i = 0; i < categoryIds.length; i++) {
6692 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
6693
6694 if ((i + 1) < categoryIds.length) {
6695 query.append(WHERE_OR);
6696 }
6697 }
6698
6699 query.append(StringPool.CLOSE_PARENTHESIS);
6700
6701 conjunctionable = true;
6702 }
6703
6704 if (conjunctionable) {
6705 query.append(WHERE_AND);
6706 }
6707
6708 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
6709
6710 conjunctionable = true;
6711
6712 if (!getDB().isSupportsInlineDistinct()) {
6713 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6714 }
6715
6716 if (orderByComparator != null) {
6717 if (getDB().isSupportsInlineDistinct()) {
6718 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6719 orderByComparator);
6720 }
6721 else {
6722 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6723 orderByComparator);
6724 }
6725 }
6726
6727 else {
6728 if (getDB().isSupportsInlineDistinct()) {
6729 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6730 }
6731 else {
6732 query.append(MBThreadModelImpl.ORDER_BY_SQL);
6733 }
6734 }
6735
6736 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6737 MBThread.class.getName(),
6738 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6739
6740 Session session = null;
6741
6742 try {
6743 session = openSession();
6744
6745 SQLQuery q = session.createSQLQuery(sql);
6746
6747 if (getDB().isSupportsInlineDistinct()) {
6748 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6749 }
6750 else {
6751 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6752 }
6753
6754 QueryPos qPos = QueryPos.getInstance(q);
6755
6756 qPos.add(groupId);
6757
6758 if (categoryIds != null) {
6759 qPos.add(categoryIds);
6760 }
6761
6762 qPos.add(status);
6763
6764 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
6765 }
6766 catch (Exception e) {
6767 throw processException(e);
6768 }
6769 finally {
6770 closeSession(session);
6771 }
6772 }
6773
6774
6783 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6784 int status) throws SystemException {
6785 return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
6786 QueryUtil.ALL_POS, null);
6787 }
6788
6789
6804 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6805 int status, int start, int end) throws SystemException {
6806 return findByG_NotC_S(groupId, categoryId, status, start, end, null);
6807 }
6808
6809
6825 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6826 int status, int start, int end, OrderByComparator orderByComparator)
6827 throws SystemException {
6828 FinderPath finderPath = null;
6829 Object[] finderArgs = null;
6830
6831 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6832 (orderByComparator == null)) {
6833 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTC_S;
6834 finderArgs = new Object[] { groupId, categoryId, status };
6835 }
6836 else {
6837 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S;
6838 finderArgs = new Object[] {
6839 groupId, categoryId, status,
6840
6841 start, end, orderByComparator
6842 };
6843 }
6844
6845 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6846 finderArgs, this);
6847
6848 if ((list != null) && !list.isEmpty()) {
6849 for (MBThread mbThread : list) {
6850 if ((groupId != mbThread.getGroupId()) ||
6851 (categoryId != mbThread.getCategoryId()) ||
6852 (status != mbThread.getStatus())) {
6853 list = null;
6854
6855 break;
6856 }
6857 }
6858 }
6859
6860 if (list == null) {
6861 StringBundler query = null;
6862
6863 if (orderByComparator != null) {
6864 query = new StringBundler(5 +
6865 (orderByComparator.getOrderByFields().length * 3));
6866 }
6867 else {
6868 query = new StringBundler(5);
6869 }
6870
6871 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6872
6873 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
6874
6875 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
6876
6877 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
6878
6879 if (orderByComparator != null) {
6880 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6881 orderByComparator);
6882 }
6883
6884 else {
6885 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6886 }
6887
6888 String sql = query.toString();
6889
6890 Session session = null;
6891
6892 try {
6893 session = openSession();
6894
6895 Query q = session.createQuery(sql);
6896
6897 QueryPos qPos = QueryPos.getInstance(q);
6898
6899 qPos.add(groupId);
6900
6901 qPos.add(categoryId);
6902
6903 qPos.add(status);
6904
6905 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
6906 end);
6907 }
6908 catch (Exception e) {
6909 throw processException(e);
6910 }
6911 finally {
6912 if (list == null) {
6913 FinderCacheUtil.removeResult(finderPath, finderArgs);
6914 }
6915 else {
6916 cacheResult(list);
6917
6918 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6919 }
6920
6921 closeSession(session);
6922 }
6923 }
6924
6925 return list;
6926 }
6927
6928
6943 public MBThread findByG_NotC_S_First(long groupId, long categoryId,
6944 int status, OrderByComparator orderByComparator)
6945 throws NoSuchThreadException, SystemException {
6946 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
6947 orderByComparator);
6948
6949 if (list.isEmpty()) {
6950 StringBundler msg = new StringBundler(8);
6951
6952 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6953
6954 msg.append("groupId=");
6955 msg.append(groupId);
6956
6957 msg.append(", categoryId=");
6958 msg.append(categoryId);
6959
6960 msg.append(", status=");
6961 msg.append(status);
6962
6963 msg.append(StringPool.CLOSE_CURLY_BRACE);
6964
6965 throw new NoSuchThreadException(msg.toString());
6966 }
6967 else {
6968 return list.get(0);
6969 }
6970 }
6971
6972
6987 public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
6988 int status, OrderByComparator orderByComparator)
6989 throws NoSuchThreadException, SystemException {
6990 int count = countByG_NotC_S(groupId, categoryId, status);
6991
6992 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
6993 count - 1, count, orderByComparator);
6994
6995 if (list.isEmpty()) {
6996 StringBundler msg = new StringBundler(8);
6997
6998 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6999
7000 msg.append("groupId=");
7001 msg.append(groupId);
7002
7003 msg.append(", categoryId=");
7004 msg.append(categoryId);
7005
7006 msg.append(", status=");
7007 msg.append(status);
7008
7009 msg.append(StringPool.CLOSE_CURLY_BRACE);
7010
7011 throw new NoSuchThreadException(msg.toString());
7012 }
7013 else {
7014 return list.get(0);
7015 }
7016 }
7017
7018
7034 public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
7035 long categoryId, int status, OrderByComparator orderByComparator)
7036 throws NoSuchThreadException, SystemException {
7037 MBThread mbThread = findByPrimaryKey(threadId);
7038
7039 Session session = null;
7040
7041 try {
7042 session = openSession();
7043
7044 MBThread[] array = new MBThreadImpl[3];
7045
7046 array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
7047 categoryId, status, orderByComparator, true);
7048
7049 array[1] = mbThread;
7050
7051 array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
7052 categoryId, status, orderByComparator, false);
7053
7054 return array;
7055 }
7056 catch (Exception e) {
7057 throw processException(e);
7058 }
7059 finally {
7060 closeSession(session);
7061 }
7062 }
7063
7064 protected MBThread getByG_NotC_S_PrevAndNext(Session session,
7065 MBThread mbThread, long groupId, long categoryId, int status,
7066 OrderByComparator orderByComparator, boolean previous) {
7067 StringBundler query = null;
7068
7069 if (orderByComparator != null) {
7070 query = new StringBundler(6 +
7071 (orderByComparator.getOrderByFields().length * 6));
7072 }
7073 else {
7074 query = new StringBundler(3);
7075 }
7076
7077 query.append(_SQL_SELECT_MBTHREAD_WHERE);
7078
7079 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7080
7081 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7082
7083 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7084
7085 if (orderByComparator != null) {
7086 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7087
7088 if (orderByConditionFields.length > 0) {
7089 query.append(WHERE_AND);
7090 }
7091
7092 for (int i = 0; i < orderByConditionFields.length; i++) {
7093 query.append(_ORDER_BY_ENTITY_ALIAS);
7094 query.append(orderByConditionFields[i]);
7095
7096 if ((i + 1) < orderByConditionFields.length) {
7097 if (orderByComparator.isAscending() ^ previous) {
7098 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7099 }
7100 else {
7101 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7102 }
7103 }
7104 else {
7105 if (orderByComparator.isAscending() ^ previous) {
7106 query.append(WHERE_GREATER_THAN);
7107 }
7108 else {
7109 query.append(WHERE_LESSER_THAN);
7110 }
7111 }
7112 }
7113
7114 query.append(ORDER_BY_CLAUSE);
7115
7116 String[] orderByFields = orderByComparator.getOrderByFields();
7117
7118 for (int i = 0; i < orderByFields.length; i++) {
7119 query.append(_ORDER_BY_ENTITY_ALIAS);
7120 query.append(orderByFields[i]);
7121
7122 if ((i + 1) < orderByFields.length) {
7123 if (orderByComparator.isAscending() ^ previous) {
7124 query.append(ORDER_BY_ASC_HAS_NEXT);
7125 }
7126 else {
7127 query.append(ORDER_BY_DESC_HAS_NEXT);
7128 }
7129 }
7130 else {
7131 if (orderByComparator.isAscending() ^ previous) {
7132 query.append(ORDER_BY_ASC);
7133 }
7134 else {
7135 query.append(ORDER_BY_DESC);
7136 }
7137 }
7138 }
7139 }
7140
7141 else {
7142 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7143 }
7144
7145 String sql = query.toString();
7146
7147 Query q = session.createQuery(sql);
7148
7149 q.setFirstResult(0);
7150 q.setMaxResults(2);
7151
7152 QueryPos qPos = QueryPos.getInstance(q);
7153
7154 qPos.add(groupId);
7155
7156 qPos.add(categoryId);
7157
7158 qPos.add(status);
7159
7160 if (orderByComparator != null) {
7161 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7162
7163 for (Object value : values) {
7164 qPos.add(value);
7165 }
7166 }
7167
7168 List<MBThread> list = q.list();
7169
7170 if (list.size() == 2) {
7171 return list.get(1);
7172 }
7173 else {
7174 return null;
7175 }
7176 }
7177
7178
7187 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7188 int status) throws SystemException {
7189 return filterFindByG_NotC_S(groupId, categoryId, status,
7190 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7191 }
7192
7193
7208 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7209 int status, int start, int end) throws SystemException {
7210 return filterFindByG_NotC_S(groupId, categoryId, status, start, end,
7211 null);
7212 }
7213
7214
7230 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7231 int status, int start, int end, OrderByComparator orderByComparator)
7232 throws SystemException {
7233 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7234 return findByG_NotC_S(groupId, categoryId, status, start, end,
7235 orderByComparator);
7236 }
7237
7238 StringBundler query = null;
7239
7240 if (orderByComparator != null) {
7241 query = new StringBundler(5 +
7242 (orderByComparator.getOrderByFields().length * 3));
7243 }
7244 else {
7245 query = new StringBundler(5);
7246 }
7247
7248 if (getDB().isSupportsInlineDistinct()) {
7249 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7250 }
7251 else {
7252 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7253 }
7254
7255 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7256
7257 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7258
7259 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7260
7261 if (!getDB().isSupportsInlineDistinct()) {
7262 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7263 }
7264
7265 if (orderByComparator != null) {
7266 if (getDB().isSupportsInlineDistinct()) {
7267 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7268 orderByComparator);
7269 }
7270 else {
7271 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7272 orderByComparator);
7273 }
7274 }
7275
7276 else {
7277 if (getDB().isSupportsInlineDistinct()) {
7278 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7279 }
7280 else {
7281 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7282 }
7283 }
7284
7285 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7286 MBThread.class.getName(),
7287 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7288
7289 Session session = null;
7290
7291 try {
7292 session = openSession();
7293
7294 SQLQuery q = session.createSQLQuery(sql);
7295
7296 if (getDB().isSupportsInlineDistinct()) {
7297 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7298 }
7299 else {
7300 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7301 }
7302
7303 QueryPos qPos = QueryPos.getInstance(q);
7304
7305 qPos.add(groupId);
7306
7307 qPos.add(categoryId);
7308
7309 qPos.add(status);
7310
7311 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
7312 }
7313 catch (Exception e) {
7314 throw processException(e);
7315 }
7316 finally {
7317 closeSession(session);
7318 }
7319 }
7320
7321
7333 public MBThread[] filterFindByG_NotC_S_PrevAndNext(long threadId,
7334 long groupId, long categoryId, int status,
7335 OrderByComparator orderByComparator)
7336 throws NoSuchThreadException, SystemException {
7337 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7338 return findByG_NotC_S_PrevAndNext(threadId, groupId, categoryId,
7339 status, orderByComparator);
7340 }
7341
7342 MBThread mbThread = findByPrimaryKey(threadId);
7343
7344 Session session = null;
7345
7346 try {
7347 session = openSession();
7348
7349 MBThread[] array = new MBThreadImpl[3];
7350
7351 array[0] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
7352 groupId, categoryId, status, orderByComparator, true);
7353
7354 array[1] = mbThread;
7355
7356 array[2] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
7357 groupId, categoryId, status, orderByComparator, false);
7358
7359 return array;
7360 }
7361 catch (Exception e) {
7362 throw processException(e);
7363 }
7364 finally {
7365 closeSession(session);
7366 }
7367 }
7368
7369 protected MBThread filterGetByG_NotC_S_PrevAndNext(Session session,
7370 MBThread mbThread, long groupId, long categoryId, int status,
7371 OrderByComparator orderByComparator, boolean previous) {
7372 StringBundler query = null;
7373
7374 if (orderByComparator != null) {
7375 query = new StringBundler(6 +
7376 (orderByComparator.getOrderByFields().length * 6));
7377 }
7378 else {
7379 query = new StringBundler(3);
7380 }
7381
7382 if (getDB().isSupportsInlineDistinct()) {
7383 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7384 }
7385 else {
7386 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7387 }
7388
7389 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7390
7391 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7392
7393 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7394
7395 if (!getDB().isSupportsInlineDistinct()) {
7396 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7397 }
7398
7399 if (orderByComparator != null) {
7400 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7401
7402 if (orderByConditionFields.length > 0) {
7403 query.append(WHERE_AND);
7404 }
7405
7406 for (int i = 0; i < orderByConditionFields.length; i++) {
7407 if (getDB().isSupportsInlineDistinct()) {
7408 query.append(_ORDER_BY_ENTITY_ALIAS);
7409 }
7410 else {
7411 query.append(_ORDER_BY_ENTITY_TABLE);
7412 }
7413
7414 query.append(orderByConditionFields[i]);
7415
7416 if ((i + 1) < orderByConditionFields.length) {
7417 if (orderByComparator.isAscending() ^ previous) {
7418 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7419 }
7420 else {
7421 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7422 }
7423 }
7424 else {
7425 if (orderByComparator.isAscending() ^ previous) {
7426 query.append(WHERE_GREATER_THAN);
7427 }
7428 else {
7429 query.append(WHERE_LESSER_THAN);
7430 }
7431 }
7432 }
7433
7434 query.append(ORDER_BY_CLAUSE);
7435
7436 String[] orderByFields = orderByComparator.getOrderByFields();
7437
7438 for (int i = 0; i < orderByFields.length; i++) {
7439 if (getDB().isSupportsInlineDistinct()) {
7440 query.append(_ORDER_BY_ENTITY_ALIAS);
7441 }
7442 else {
7443 query.append(_ORDER_BY_ENTITY_TABLE);
7444 }
7445
7446 query.append(orderByFields[i]);
7447
7448 if ((i + 1) < orderByFields.length) {
7449 if (orderByComparator.isAscending() ^ previous) {
7450 query.append(ORDER_BY_ASC_HAS_NEXT);
7451 }
7452 else {
7453 query.append(ORDER_BY_DESC_HAS_NEXT);
7454 }
7455 }
7456 else {
7457 if (orderByComparator.isAscending() ^ previous) {
7458 query.append(ORDER_BY_ASC);
7459 }
7460 else {
7461 query.append(ORDER_BY_DESC);
7462 }
7463 }
7464 }
7465 }
7466
7467 else {
7468 if (getDB().isSupportsInlineDistinct()) {
7469 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7470 }
7471 else {
7472 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7473 }
7474 }
7475
7476 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7477 MBThread.class.getName(),
7478 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7479
7480 SQLQuery q = session.createSQLQuery(sql);
7481
7482 q.setFirstResult(0);
7483 q.setMaxResults(2);
7484
7485 if (getDB().isSupportsInlineDistinct()) {
7486 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7487 }
7488 else {
7489 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7490 }
7491
7492 QueryPos qPos = QueryPos.getInstance(q);
7493
7494 qPos.add(groupId);
7495
7496 qPos.add(categoryId);
7497
7498 qPos.add(status);
7499
7500 if (orderByComparator != null) {
7501 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7502
7503 for (Object value : values) {
7504 qPos.add(value);
7505 }
7506 }
7507
7508 List<MBThread> list = q.list();
7509
7510 if (list.size() == 2) {
7511 return list.get(1);
7512 }
7513 else {
7514 return null;
7515 }
7516 }
7517
7518
7524 public List<MBThread> findAll() throws SystemException {
7525 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7526 }
7527
7528
7540 public List<MBThread> findAll(int start, int end) throws SystemException {
7541 return findAll(start, end, null);
7542 }
7543
7544
7557 public List<MBThread> findAll(int start, int end,
7558 OrderByComparator orderByComparator) throws SystemException {
7559 FinderPath finderPath = null;
7560 Object[] finderArgs = new Object[] { start, end, orderByComparator };
7561
7562 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7563 (orderByComparator == null)) {
7564 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7565 finderArgs = FINDER_ARGS_EMPTY;
7566 }
7567 else {
7568 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7569 finderArgs = new Object[] { start, end, orderByComparator };
7570 }
7571
7572 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
7573 finderArgs, this);
7574
7575 if (list == null) {
7576 StringBundler query = null;
7577 String sql = null;
7578
7579 if (orderByComparator != null) {
7580 query = new StringBundler(2 +
7581 (orderByComparator.getOrderByFields().length * 3));
7582
7583 query.append(_SQL_SELECT_MBTHREAD);
7584
7585 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7586 orderByComparator);
7587
7588 sql = query.toString();
7589 }
7590 else {
7591 sql = _SQL_SELECT_MBTHREAD.concat(MBThreadModelImpl.ORDER_BY_JPQL);
7592 }
7593
7594 Session session = null;
7595
7596 try {
7597 session = openSession();
7598
7599 Query q = session.createQuery(sql);
7600
7601 if (orderByComparator == null) {
7602 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7603 start, end, false);
7604
7605 Collections.sort(list);
7606 }
7607 else {
7608 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7609 start, end);
7610 }
7611 }
7612 catch (Exception e) {
7613 throw processException(e);
7614 }
7615 finally {
7616 if (list == null) {
7617 FinderCacheUtil.removeResult(finderPath, finderArgs);
7618 }
7619 else {
7620 cacheResult(list);
7621
7622 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7623 }
7624
7625 closeSession(session);
7626 }
7627 }
7628
7629 return list;
7630 }
7631
7632
7638 public void removeByGroupId(long groupId) throws SystemException {
7639 for (MBThread mbThread : findByGroupId(groupId)) {
7640 remove(mbThread);
7641 }
7642 }
7643
7644
7650 public void removeByRootMessageId(long rootMessageId)
7651 throws NoSuchThreadException, SystemException {
7652 MBThread mbThread = findByRootMessageId(rootMessageId);
7653
7654 remove(mbThread);
7655 }
7656
7657
7664 public void removeByG_C(long groupId, long categoryId)
7665 throws SystemException {
7666 for (MBThread mbThread : findByG_C(groupId, categoryId)) {
7667 remove(mbThread);
7668 }
7669 }
7670
7671
7678 public void removeByG_NotC(long groupId, long categoryId)
7679 throws SystemException {
7680 for (MBThread mbThread : findByG_NotC(groupId, categoryId)) {
7681 remove(mbThread);
7682 }
7683 }
7684
7685
7692 public void removeByG_S(long groupId, int status) throws SystemException {
7693 for (MBThread mbThread : findByG_S(groupId, status)) {
7694 remove(mbThread);
7695 }
7696 }
7697
7698
7705 public void removeByC_P(long categoryId, double priority)
7706 throws SystemException {
7707 for (MBThread mbThread : findByC_P(categoryId, priority)) {
7708 remove(mbThread);
7709 }
7710 }
7711
7712
7719 public void removeByL_P(Date lastPostDate, double priority)
7720 throws SystemException {
7721 for (MBThread mbThread : findByL_P(lastPostDate, priority)) {
7722 remove(mbThread);
7723 }
7724 }
7725
7726
7734 public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
7735 throws SystemException {
7736 for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate)) {
7737 remove(mbThread);
7738 }
7739 }
7740
7741
7749 public void removeByG_C_S(long groupId, long categoryId, int status)
7750 throws SystemException {
7751 for (MBThread mbThread : findByG_C_S(groupId, categoryId, status)) {
7752 remove(mbThread);
7753 }
7754 }
7755
7756
7764 public void removeByG_NotC_S(long groupId, long categoryId, int status)
7765 throws SystemException {
7766 for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status)) {
7767 remove(mbThread);
7768 }
7769 }
7770
7771
7776 public void removeAll() throws SystemException {
7777 for (MBThread mbThread : findAll()) {
7778 remove(mbThread);
7779 }
7780 }
7781
7782
7789 public int countByGroupId(long groupId) throws SystemException {
7790 Object[] finderArgs = new Object[] { groupId };
7791
7792 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
7793 finderArgs, this);
7794
7795 if (count == null) {
7796 StringBundler query = new StringBundler(2);
7797
7798 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7799
7800 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
7801
7802 String sql = query.toString();
7803
7804 Session session = null;
7805
7806 try {
7807 session = openSession();
7808
7809 Query q = session.createQuery(sql);
7810
7811 QueryPos qPos = QueryPos.getInstance(q);
7812
7813 qPos.add(groupId);
7814
7815 count = (Long)q.uniqueResult();
7816 }
7817 catch (Exception e) {
7818 throw processException(e);
7819 }
7820 finally {
7821 if (count == null) {
7822 count = Long.valueOf(0);
7823 }
7824
7825 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
7826 finderArgs, count);
7827
7828 closeSession(session);
7829 }
7830 }
7831
7832 return count.intValue();
7833 }
7834
7835
7842 public int filterCountByGroupId(long groupId) throws SystemException {
7843 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7844 return countByGroupId(groupId);
7845 }
7846
7847 StringBundler query = new StringBundler(2);
7848
7849 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7850
7851 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
7852
7853 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7854 MBThread.class.getName(),
7855 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7856
7857 Session session = null;
7858
7859 try {
7860 session = openSession();
7861
7862 SQLQuery q = session.createSQLQuery(sql);
7863
7864 q.addScalar(COUNT_COLUMN_NAME,
7865 com.liferay.portal.kernel.dao.orm.Type.LONG);
7866
7867 QueryPos qPos = QueryPos.getInstance(q);
7868
7869 qPos.add(groupId);
7870
7871 Long count = (Long)q.uniqueResult();
7872
7873 return count.intValue();
7874 }
7875 catch (Exception e) {
7876 throw processException(e);
7877 }
7878 finally {
7879 closeSession(session);
7880 }
7881 }
7882
7883
7890 public int countByRootMessageId(long rootMessageId)
7891 throws SystemException {
7892 Object[] finderArgs = new Object[] { rootMessageId };
7893
7894 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
7895 finderArgs, this);
7896
7897 if (count == null) {
7898 StringBundler query = new StringBundler(2);
7899
7900 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7901
7902 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
7903
7904 String sql = query.toString();
7905
7906 Session session = null;
7907
7908 try {
7909 session = openSession();
7910
7911 Query q = session.createQuery(sql);
7912
7913 QueryPos qPos = QueryPos.getInstance(q);
7914
7915 qPos.add(rootMessageId);
7916
7917 count = (Long)q.uniqueResult();
7918 }
7919 catch (Exception e) {
7920 throw processException(e);
7921 }
7922 finally {
7923 if (count == null) {
7924 count = Long.valueOf(0);
7925 }
7926
7927 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
7928 finderArgs, count);
7929
7930 closeSession(session);
7931 }
7932 }
7933
7934 return count.intValue();
7935 }
7936
7937
7945 public int countByG_C(long groupId, long categoryId)
7946 throws SystemException {
7947 Object[] finderArgs = new Object[] { groupId, categoryId };
7948
7949 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
7950 finderArgs, this);
7951
7952 if (count == null) {
7953 StringBundler query = new StringBundler(3);
7954
7955 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7956
7957 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
7958
7959 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
7960
7961 String sql = query.toString();
7962
7963 Session session = null;
7964
7965 try {
7966 session = openSession();
7967
7968 Query q = session.createQuery(sql);
7969
7970 QueryPos qPos = QueryPos.getInstance(q);
7971
7972 qPos.add(groupId);
7973
7974 qPos.add(categoryId);
7975
7976 count = (Long)q.uniqueResult();
7977 }
7978 catch (Exception e) {
7979 throw processException(e);
7980 }
7981 finally {
7982 if (count == null) {
7983 count = Long.valueOf(0);
7984 }
7985
7986 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
7987 count);
7988
7989 closeSession(session);
7990 }
7991 }
7992
7993 return count.intValue();
7994 }
7995
7996
8004 public int countByG_C(long groupId, long[] categoryIds)
8005 throws SystemException {
8006 Object[] finderArgs = new Object[] {
8007 groupId, StringUtil.merge(categoryIds)
8008 };
8009
8010 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
8011 finderArgs, this);
8012
8013 if (count == null) {
8014 StringBundler query = new StringBundler();
8015
8016 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8017
8018 boolean conjunctionable = false;
8019
8020 if (conjunctionable) {
8021 query.append(WHERE_AND);
8022 }
8023
8024 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
8025
8026 conjunctionable = true;
8027
8028 if ((categoryIds == null) || (categoryIds.length > 0)) {
8029 if (conjunctionable) {
8030 query.append(WHERE_AND);
8031 }
8032
8033 query.append(StringPool.OPEN_PARENTHESIS);
8034
8035 for (int i = 0; i < categoryIds.length; i++) {
8036 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
8037
8038 if ((i + 1) < categoryIds.length) {
8039 query.append(WHERE_OR);
8040 }
8041 }
8042
8043 query.append(StringPool.CLOSE_PARENTHESIS);
8044
8045 conjunctionable = true;
8046 }
8047
8048 String sql = query.toString();
8049
8050 Session session = null;
8051
8052 try {
8053 session = openSession();
8054
8055 Query q = session.createQuery(sql);
8056
8057 QueryPos qPos = QueryPos.getInstance(q);
8058
8059 qPos.add(groupId);
8060
8061 if (categoryIds != null) {
8062 qPos.add(categoryIds);
8063 }
8064
8065 count = (Long)q.uniqueResult();
8066 }
8067 catch (Exception e) {
8068 throw processException(e);
8069 }
8070 finally {
8071 if (count == null) {
8072 count = Long.valueOf(0);
8073 }
8074
8075 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
8076 finderArgs, count);
8077
8078 closeSession(session);
8079 }
8080 }
8081
8082 return count.intValue();
8083 }
8084
8085
8093 public int filterCountByG_C(long groupId, long categoryId)
8094 throws SystemException {
8095 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8096 return countByG_C(groupId, categoryId);
8097 }
8098
8099 StringBundler query = new StringBundler(3);
8100
8101 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8102
8103 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
8104
8105 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
8106
8107 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8108 MBThread.class.getName(),
8109 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8110
8111 Session session = null;
8112
8113 try {
8114 session = openSession();
8115
8116 SQLQuery q = session.createSQLQuery(sql);
8117
8118 q.addScalar(COUNT_COLUMN_NAME,
8119 com.liferay.portal.kernel.dao.orm.Type.LONG);
8120
8121 QueryPos qPos = QueryPos.getInstance(q);
8122
8123 qPos.add(groupId);
8124
8125 qPos.add(categoryId);
8126
8127 Long count = (Long)q.uniqueResult();
8128
8129 return count.intValue();
8130 }
8131 catch (Exception e) {
8132 throw processException(e);
8133 }
8134 finally {
8135 closeSession(session);
8136 }
8137 }
8138
8139
8147 public int filterCountByG_C(long groupId, long[] categoryIds)
8148 throws SystemException {
8149 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8150 return countByG_C(groupId, categoryIds);
8151 }
8152
8153 StringBundler query = new StringBundler();
8154
8155 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8156
8157 boolean conjunctionable = false;
8158
8159 if (conjunctionable) {
8160 query.append(WHERE_AND);
8161 }
8162
8163 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
8164
8165 conjunctionable = true;
8166
8167 if ((categoryIds == null) || (categoryIds.length > 0)) {
8168 if (conjunctionable) {
8169 query.append(WHERE_AND);
8170 }
8171
8172 query.append(StringPool.OPEN_PARENTHESIS);
8173
8174 for (int i = 0; i < categoryIds.length; i++) {
8175 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
8176
8177 if ((i + 1) < categoryIds.length) {
8178 query.append(WHERE_OR);
8179 }
8180 }
8181
8182 query.append(StringPool.CLOSE_PARENTHESIS);
8183
8184 conjunctionable = true;
8185 }
8186
8187 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8188 MBThread.class.getName(),
8189 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8190
8191 Session session = null;
8192
8193 try {
8194 session = openSession();
8195
8196 SQLQuery q = session.createSQLQuery(sql);
8197
8198 q.addScalar(COUNT_COLUMN_NAME,
8199 com.liferay.portal.kernel.dao.orm.Type.LONG);
8200
8201 QueryPos qPos = QueryPos.getInstance(q);
8202
8203 qPos.add(groupId);
8204
8205 if (categoryIds != null) {
8206 qPos.add(categoryIds);
8207 }
8208
8209 Long count = (Long)q.uniqueResult();
8210
8211 return count.intValue();
8212 }
8213 catch (Exception e) {
8214 throw processException(e);
8215 }
8216 finally {
8217 closeSession(session);
8218 }
8219 }
8220
8221
8229 public int countByG_NotC(long groupId, long categoryId)
8230 throws SystemException {
8231 Object[] finderArgs = new Object[] { groupId, categoryId };
8232
8233 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTC,
8234 finderArgs, this);
8235
8236 if (count == null) {
8237 StringBundler query = new StringBundler(3);
8238
8239 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8240
8241 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
8242
8243 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
8244
8245 String sql = query.toString();
8246
8247 Session session = null;
8248
8249 try {
8250 session = openSession();
8251
8252 Query q = session.createQuery(sql);
8253
8254 QueryPos qPos = QueryPos.getInstance(q);
8255
8256 qPos.add(groupId);
8257
8258 qPos.add(categoryId);
8259
8260 count = (Long)q.uniqueResult();
8261 }
8262 catch (Exception e) {
8263 throw processException(e);
8264 }
8265 finally {
8266 if (count == null) {
8267 count = Long.valueOf(0);
8268 }
8269
8270 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTC,
8271 finderArgs, count);
8272
8273 closeSession(session);
8274 }
8275 }
8276
8277 return count.intValue();
8278 }
8279
8280
8288 public int filterCountByG_NotC(long groupId, long categoryId)
8289 throws SystemException {
8290 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8291 return countByG_NotC(groupId, categoryId);
8292 }
8293
8294 StringBundler query = new StringBundler(3);
8295
8296 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8297
8298 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
8299
8300 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
8301
8302 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8303 MBThread.class.getName(),
8304 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8305
8306 Session session = null;
8307
8308 try {
8309 session = openSession();
8310
8311 SQLQuery q = session.createSQLQuery(sql);
8312
8313 q.addScalar(COUNT_COLUMN_NAME,
8314 com.liferay.portal.kernel.dao.orm.Type.LONG);
8315
8316 QueryPos qPos = QueryPos.getInstance(q);
8317
8318 qPos.add(groupId);
8319
8320 qPos.add(categoryId);
8321
8322 Long count = (Long)q.uniqueResult();
8323
8324 return count.intValue();
8325 }
8326 catch (Exception e) {
8327 throw processException(e);
8328 }
8329 finally {
8330 closeSession(session);
8331 }
8332 }
8333
8334
8342 public int countByG_S(long groupId, int status) throws SystemException {
8343 Object[] finderArgs = new Object[] { groupId, status };
8344
8345 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
8346 finderArgs, this);
8347
8348 if (count == null) {
8349 StringBundler query = new StringBundler(3);
8350
8351 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8352
8353 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
8354
8355 query.append(_FINDER_COLUMN_G_S_STATUS_2);
8356
8357 String sql = query.toString();
8358
8359 Session session = null;
8360
8361 try {
8362 session = openSession();
8363
8364 Query q = session.createQuery(sql);
8365
8366 QueryPos qPos = QueryPos.getInstance(q);
8367
8368 qPos.add(groupId);
8369
8370 qPos.add(status);
8371
8372 count = (Long)q.uniqueResult();
8373 }
8374 catch (Exception e) {
8375 throw processException(e);
8376 }
8377 finally {
8378 if (count == null) {
8379 count = Long.valueOf(0);
8380 }
8381
8382 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
8383 count);
8384
8385 closeSession(session);
8386 }
8387 }
8388
8389 return count.intValue();
8390 }
8391
8392
8400 public int filterCountByG_S(long groupId, int status)
8401 throws SystemException {
8402 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8403 return countByG_S(groupId, status);
8404 }
8405
8406 StringBundler query = new StringBundler(3);
8407
8408 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8409
8410 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
8411
8412 query.append(_FINDER_COLUMN_G_S_STATUS_2);
8413
8414 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8415 MBThread.class.getName(),
8416 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8417
8418 Session session = null;
8419
8420 try {
8421 session = openSession();
8422
8423 SQLQuery q = session.createSQLQuery(sql);
8424
8425 q.addScalar(COUNT_COLUMN_NAME,
8426 com.liferay.portal.kernel.dao.orm.Type.LONG);
8427
8428 QueryPos qPos = QueryPos.getInstance(q);
8429
8430 qPos.add(groupId);
8431
8432 qPos.add(status);
8433
8434 Long count = (Long)q.uniqueResult();
8435
8436 return count.intValue();
8437 }
8438 catch (Exception e) {
8439 throw processException(e);
8440 }
8441 finally {
8442 closeSession(session);
8443 }
8444 }
8445
8446
8454 public int countByC_P(long categoryId, double priority)
8455 throws SystemException {
8456 Object[] finderArgs = new Object[] { categoryId, priority };
8457
8458 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
8459 finderArgs, this);
8460
8461 if (count == null) {
8462 StringBundler query = new StringBundler(3);
8463
8464 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8465
8466 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
8467
8468 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
8469
8470 String sql = query.toString();
8471
8472 Session session = null;
8473
8474 try {
8475 session = openSession();
8476
8477 Query q = session.createQuery(sql);
8478
8479 QueryPos qPos = QueryPos.getInstance(q);
8480
8481 qPos.add(categoryId);
8482
8483 qPos.add(priority);
8484
8485 count = (Long)q.uniqueResult();
8486 }
8487 catch (Exception e) {
8488 throw processException(e);
8489 }
8490 finally {
8491 if (count == null) {
8492 count = Long.valueOf(0);
8493 }
8494
8495 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
8496 count);
8497
8498 closeSession(session);
8499 }
8500 }
8501
8502 return count.intValue();
8503 }
8504
8505
8513 public int countByL_P(Date lastPostDate, double priority)
8514 throws SystemException {
8515 Object[] finderArgs = new Object[] { lastPostDate, priority };
8516
8517 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_L_P,
8518 finderArgs, this);
8519
8520 if (count == null) {
8521 StringBundler query = new StringBundler(3);
8522
8523 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8524
8525 if (lastPostDate == null) {
8526 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
8527 }
8528 else {
8529 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
8530 }
8531
8532 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
8533
8534 String sql = query.toString();
8535
8536 Session session = null;
8537
8538 try {
8539 session = openSession();
8540
8541 Query q = session.createQuery(sql);
8542
8543 QueryPos qPos = QueryPos.getInstance(q);
8544
8545 if (lastPostDate != null) {
8546 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8547 }
8548
8549 qPos.add(priority);
8550
8551 count = (Long)q.uniqueResult();
8552 }
8553 catch (Exception e) {
8554 throw processException(e);
8555 }
8556 finally {
8557 if (count == null) {
8558 count = Long.valueOf(0);
8559 }
8560
8561 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_L_P, finderArgs,
8562 count);
8563
8564 closeSession(session);
8565 }
8566 }
8567
8568 return count.intValue();
8569 }
8570
8571
8580 public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
8581 throws SystemException {
8582 Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
8583
8584 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_L,
8585 finderArgs, this);
8586
8587 if (count == null) {
8588 StringBundler query = new StringBundler(4);
8589
8590 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8591
8592 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
8593
8594 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
8595
8596 if (lastPostDate == null) {
8597 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
8598 }
8599 else {
8600 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
8601 }
8602
8603 String sql = query.toString();
8604
8605 Session session = null;
8606
8607 try {
8608 session = openSession();
8609
8610 Query q = session.createQuery(sql);
8611
8612 QueryPos qPos = QueryPos.getInstance(q);
8613
8614 qPos.add(groupId);
8615
8616 qPos.add(categoryId);
8617
8618 if (lastPostDate != null) {
8619 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8620 }
8621
8622 count = (Long)q.uniqueResult();
8623 }
8624 catch (Exception e) {
8625 throw processException(e);
8626 }
8627 finally {
8628 if (count == null) {
8629 count = Long.valueOf(0);
8630 }
8631
8632 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_L,
8633 finderArgs, count);
8634
8635 closeSession(session);
8636 }
8637 }
8638
8639 return count.intValue();
8640 }
8641
8642
8651 public int filterCountByG_C_L(long groupId, long categoryId,
8652 Date lastPostDate) throws SystemException {
8653 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8654 return countByG_C_L(groupId, categoryId, lastPostDate);
8655 }
8656
8657 StringBundler query = new StringBundler(4);
8658
8659 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8660
8661 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
8662
8663 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
8664
8665 if (lastPostDate == null) {
8666 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
8667 }
8668 else {
8669 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
8670 }
8671
8672 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8673 MBThread.class.getName(),
8674 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8675
8676 Session session = null;
8677
8678 try {
8679 session = openSession();
8680
8681 SQLQuery q = session.createSQLQuery(sql);
8682
8683 q.addScalar(COUNT_COLUMN_NAME,
8684 com.liferay.portal.kernel.dao.orm.Type.LONG);
8685
8686 QueryPos qPos = QueryPos.getInstance(q);
8687
8688 qPos.add(groupId);
8689
8690 qPos.add(categoryId);
8691
8692 if (lastPostDate != null) {
8693 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8694 }
8695
8696 Long count = (Long)q.uniqueResult();
8697
8698 return count.intValue();
8699 }
8700 catch (Exception e) {
8701 throw processException(e);
8702 }
8703 finally {
8704 closeSession(session);
8705 }
8706 }
8707
8708
8717 public int countByG_C_S(long groupId, long categoryId, int status)
8718 throws SystemException {
8719 Object[] finderArgs = new Object[] { groupId, categoryId, status };
8720
8721 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
8722 finderArgs, this);
8723
8724 if (count == null) {
8725 StringBundler query = new StringBundler(4);
8726
8727 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8728
8729 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8730
8731 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8732
8733 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8734
8735 String sql = query.toString();
8736
8737 Session session = null;
8738
8739 try {
8740 session = openSession();
8741
8742 Query q = session.createQuery(sql);
8743
8744 QueryPos qPos = QueryPos.getInstance(q);
8745
8746 qPos.add(groupId);
8747
8748 qPos.add(categoryId);
8749
8750 qPos.add(status);
8751
8752 count = (Long)q.uniqueResult();
8753 }
8754 catch (Exception e) {
8755 throw processException(e);
8756 }
8757 finally {
8758 if (count == null) {
8759 count = Long.valueOf(0);
8760 }
8761
8762 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
8763 finderArgs, count);
8764
8765 closeSession(session);
8766 }
8767 }
8768
8769 return count.intValue();
8770 }
8771
8772
8781 public int countByG_C_S(long groupId, long[] categoryIds, int status)
8782 throws SystemException {
8783 Object[] finderArgs = new Object[] {
8784 groupId, StringUtil.merge(categoryIds), status
8785 };
8786
8787 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8788 finderArgs, this);
8789
8790 if (count == null) {
8791 StringBundler query = new StringBundler();
8792
8793 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8794
8795 boolean conjunctionable = false;
8796
8797 if (conjunctionable) {
8798 query.append(WHERE_AND);
8799 }
8800
8801 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
8802
8803 conjunctionable = true;
8804
8805 if ((categoryIds == null) || (categoryIds.length > 0)) {
8806 if (conjunctionable) {
8807 query.append(WHERE_AND);
8808 }
8809
8810 query.append(StringPool.OPEN_PARENTHESIS);
8811
8812 for (int i = 0; i < categoryIds.length; i++) {
8813 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
8814
8815 if ((i + 1) < categoryIds.length) {
8816 query.append(WHERE_OR);
8817 }
8818 }
8819
8820 query.append(StringPool.CLOSE_PARENTHESIS);
8821
8822 conjunctionable = true;
8823 }
8824
8825 if (conjunctionable) {
8826 query.append(WHERE_AND);
8827 }
8828
8829 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
8830
8831 conjunctionable = true;
8832
8833 String sql = query.toString();
8834
8835 Session session = null;
8836
8837 try {
8838 session = openSession();
8839
8840 Query q = session.createQuery(sql);
8841
8842 QueryPos qPos = QueryPos.getInstance(q);
8843
8844 qPos.add(groupId);
8845
8846 if (categoryIds != null) {
8847 qPos.add(categoryIds);
8848 }
8849
8850 qPos.add(status);
8851
8852 count = (Long)q.uniqueResult();
8853 }
8854 catch (Exception e) {
8855 throw processException(e);
8856 }
8857 finally {
8858 if (count == null) {
8859 count = Long.valueOf(0);
8860 }
8861
8862 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8863 finderArgs, count);
8864
8865 closeSession(session);
8866 }
8867 }
8868
8869 return count.intValue();
8870 }
8871
8872
8881 public int filterCountByG_C_S(long groupId, long categoryId, int status)
8882 throws SystemException {
8883 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8884 return countByG_C_S(groupId, categoryId, status);
8885 }
8886
8887 StringBundler query = new StringBundler(4);
8888
8889 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8890
8891 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8892
8893 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8894
8895 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8896
8897 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8898 MBThread.class.getName(),
8899 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8900
8901 Session session = null;
8902
8903 try {
8904 session = openSession();
8905
8906 SQLQuery q = session.createSQLQuery(sql);
8907
8908 q.addScalar(COUNT_COLUMN_NAME,
8909 com.liferay.portal.kernel.dao.orm.Type.LONG);
8910
8911 QueryPos qPos = QueryPos.getInstance(q);
8912
8913 qPos.add(groupId);
8914
8915 qPos.add(categoryId);
8916
8917 qPos.add(status);
8918
8919 Long count = (Long)q.uniqueResult();
8920
8921 return count.intValue();
8922 }
8923 catch (Exception e) {
8924 throw processException(e);
8925 }
8926 finally {
8927 closeSession(session);
8928 }
8929 }
8930
8931
8940 public int filterCountByG_C_S(long groupId, long[] categoryIds, int status)
8941 throws SystemException {
8942 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8943 return countByG_C_S(groupId, categoryIds, status);
8944 }
8945
8946 StringBundler query = new StringBundler();
8947
8948 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8949
8950 boolean conjunctionable = false;
8951
8952 if (conjunctionable) {
8953 query.append(WHERE_AND);
8954 }
8955
8956 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
8957
8958 conjunctionable = true;
8959
8960 if ((categoryIds == null) || (categoryIds.length > 0)) {
8961 if (conjunctionable) {
8962 query.append(WHERE_AND);
8963 }
8964
8965 query.append(StringPool.OPEN_PARENTHESIS);
8966
8967 for (int i = 0; i < categoryIds.length; i++) {
8968 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
8969
8970 if ((i + 1) < categoryIds.length) {
8971 query.append(WHERE_OR);
8972 }
8973 }
8974
8975 query.append(StringPool.CLOSE_PARENTHESIS);
8976
8977 conjunctionable = true;
8978 }
8979
8980 if (conjunctionable) {
8981 query.append(WHERE_AND);
8982 }
8983
8984 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
8985
8986 conjunctionable = true;
8987
8988 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8989 MBThread.class.getName(),
8990 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8991
8992 Session session = null;
8993
8994 try {
8995 session = openSession();
8996
8997 SQLQuery q = session.createSQLQuery(sql);
8998
8999 q.addScalar(COUNT_COLUMN_NAME,
9000 com.liferay.portal.kernel.dao.orm.Type.LONG);
9001
9002 QueryPos qPos = QueryPos.getInstance(q);
9003
9004 qPos.add(groupId);
9005
9006 if (categoryIds != null) {
9007 qPos.add(categoryIds);
9008 }
9009
9010 qPos.add(status);
9011
9012 Long count = (Long)q.uniqueResult();
9013
9014 return count.intValue();
9015 }
9016 catch (Exception e) {
9017 throw processException(e);
9018 }
9019 finally {
9020 closeSession(session);
9021 }
9022 }
9023
9024
9033 public int countByG_NotC_S(long groupId, long categoryId, int status)
9034 throws SystemException {
9035 Object[] finderArgs = new Object[] { groupId, categoryId, status };
9036
9037 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTC_S,
9038 finderArgs, this);
9039
9040 if (count == null) {
9041 StringBundler query = new StringBundler(4);
9042
9043 query.append(_SQL_COUNT_MBTHREAD_WHERE);
9044
9045 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
9046
9047 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
9048
9049 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
9050
9051 String sql = query.toString();
9052
9053 Session session = null;
9054
9055 try {
9056 session = openSession();
9057
9058 Query q = session.createQuery(sql);
9059
9060 QueryPos qPos = QueryPos.getInstance(q);
9061
9062 qPos.add(groupId);
9063
9064 qPos.add(categoryId);
9065
9066 qPos.add(status);
9067
9068 count = (Long)q.uniqueResult();
9069 }
9070 catch (Exception e) {
9071 throw processException(e);
9072 }
9073 finally {
9074 if (count == null) {
9075 count = Long.valueOf(0);
9076 }
9077
9078 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTC_S,
9079 finderArgs, count);
9080
9081 closeSession(session);
9082 }
9083 }
9084
9085 return count.intValue();
9086 }
9087
9088
9097 public int filterCountByG_NotC_S(long groupId, long categoryId, int status)
9098 throws SystemException {
9099 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9100 return countByG_NotC_S(groupId, categoryId, status);
9101 }
9102
9103 StringBundler query = new StringBundler(4);
9104
9105 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9106
9107 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
9108
9109 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
9110
9111 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
9112
9113 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9114 MBThread.class.getName(),
9115 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9116
9117 Session session = null;
9118
9119 try {
9120 session = openSession();
9121
9122 SQLQuery q = session.createSQLQuery(sql);
9123
9124 q.addScalar(COUNT_COLUMN_NAME,
9125 com.liferay.portal.kernel.dao.orm.Type.LONG);
9126
9127 QueryPos qPos = QueryPos.getInstance(q);
9128
9129 qPos.add(groupId);
9130
9131 qPos.add(categoryId);
9132
9133 qPos.add(status);
9134
9135 Long count = (Long)q.uniqueResult();
9136
9137 return count.intValue();
9138 }
9139 catch (Exception e) {
9140 throw processException(e);
9141 }
9142 finally {
9143 closeSession(session);
9144 }
9145 }
9146
9147
9153 public int countAll() throws SystemException {
9154 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9155 FINDER_ARGS_EMPTY, this);
9156
9157 if (count == null) {
9158 Session session = null;
9159
9160 try {
9161 session = openSession();
9162
9163 Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
9164
9165 count = (Long)q.uniqueResult();
9166 }
9167 catch (Exception e) {
9168 throw processException(e);
9169 }
9170 finally {
9171 if (count == null) {
9172 count = Long.valueOf(0);
9173 }
9174
9175 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
9176 FINDER_ARGS_EMPTY, count);
9177
9178 closeSession(session);
9179 }
9180 }
9181
9182 return count.intValue();
9183 }
9184
9185
9188 public void afterPropertiesSet() {
9189 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9190 com.liferay.portal.util.PropsUtil.get(
9191 "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
9192
9193 if (listenerClassNames.length > 0) {
9194 try {
9195 List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
9196
9197 for (String listenerClassName : listenerClassNames) {
9198 listenersList.add((ModelListener<MBThread>)InstanceFactory.newInstance(
9199 listenerClassName));
9200 }
9201
9202 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9203 }
9204 catch (Exception e) {
9205 _log.error(e);
9206 }
9207 }
9208 }
9209
9210 public void destroy() {
9211 EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
9212 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9213 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9214 }
9215
9216 @BeanReference(type = MBBanPersistence.class)
9217 protected MBBanPersistence mbBanPersistence;
9218 @BeanReference(type = MBCategoryPersistence.class)
9219 protected MBCategoryPersistence mbCategoryPersistence;
9220 @BeanReference(type = MBDiscussionPersistence.class)
9221 protected MBDiscussionPersistence mbDiscussionPersistence;
9222 @BeanReference(type = MBMailingListPersistence.class)
9223 protected MBMailingListPersistence mbMailingListPersistence;
9224 @BeanReference(type = MBMessagePersistence.class)
9225 protected MBMessagePersistence mbMessagePersistence;
9226 @BeanReference(type = MBStatsUserPersistence.class)
9227 protected MBStatsUserPersistence mbStatsUserPersistence;
9228 @BeanReference(type = MBThreadPersistence.class)
9229 protected MBThreadPersistence mbThreadPersistence;
9230 @BeanReference(type = MBThreadFlagPersistence.class)
9231 protected MBThreadFlagPersistence mbThreadFlagPersistence;
9232 @BeanReference(type = LockPersistence.class)
9233 protected LockPersistence lockPersistence;
9234 @BeanReference(type = ResourcePersistence.class)
9235 protected ResourcePersistence resourcePersistence;
9236 @BeanReference(type = UserPersistence.class)
9237 protected UserPersistence userPersistence;
9238 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
9239 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
9240 @BeanReference(type = AssetEntryPersistence.class)
9241 protected AssetEntryPersistence assetEntryPersistence;
9242 @BeanReference(type = RatingsStatsPersistence.class)
9243 protected RatingsStatsPersistence ratingsStatsPersistence;
9244 @BeanReference(type = SocialActivityPersistence.class)
9245 protected SocialActivityPersistence socialActivityPersistence;
9246 private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
9247 private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
9248 private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
9249 private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
9250 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ? AND mbThread.categoryId != -1";
9251 private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
9252 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
9253 private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
9254 _removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
9255 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
9256 private static final String _FINDER_COLUMN_G_C_CATEGORYID_5 = "(" +
9257 _removeConjunction(_FINDER_COLUMN_G_C_CATEGORYID_2) + ")";
9258 private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
9259 private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
9260 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9261 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
9262 private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9263 private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
9264 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL AND ";
9265 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_2 = "mbThread.lastPostDate = ? AND ";
9266 private static final String _FINDER_COLUMN_L_P_PRIORITY_2 = "mbThread.priority = ? AND mbThread.categoryId != -1";
9267 private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
9268 private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9269 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
9270 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
9271 private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9272 private static final String _FINDER_COLUMN_G_C_S_GROUPID_5 = "(" +
9273 _removeConjunction(_FINDER_COLUMN_G_C_S_GROUPID_2) + ")";
9274 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9275 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_5 = "(" +
9276 _removeConjunction(_FINDER_COLUMN_G_C_S_CATEGORYID_2) + ")";
9277 private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
9278 private static final String _FINDER_COLUMN_G_C_S_STATUS_5 = "(" +
9279 _removeConjunction(_FINDER_COLUMN_G_C_S_STATUS_2) + ")";
9280 private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9281 private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
9282 private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
9283
9284 private static String _removeConjunction(String sql) {
9285 int pos = sql.indexOf(" AND ");
9286
9287 if (pos != -1) {
9288 sql = sql.substring(0, pos);
9289 }
9290
9291 return sql;
9292 }
9293
9294 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbThread.threadId";
9295 private static final String _FILTER_SQL_SELECT_MBTHREAD_WHERE = "SELECT DISTINCT {mbThread.*} FROM MBThread mbThread WHERE ";
9296 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1 =
9297 "SELECT {MBThread.*} FROM (SELECT DISTINCT mbThread.threadId FROM MBThread mbThread WHERE ";
9298 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2 =
9299 ") TEMP_TABLE INNER JOIN MBThread ON TEMP_TABLE.threadId = MBThread.threadId";
9300 private static final String _FILTER_SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(DISTINCT mbThread.threadId) AS COUNT_VALUE FROM MBThread mbThread WHERE ";
9301 private static final String _FILTER_ENTITY_ALIAS = "mbThread";
9302 private static final String _FILTER_ENTITY_TABLE = "MBThread";
9303 private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
9304 private static final String _ORDER_BY_ENTITY_TABLE = "MBThread.";
9305 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
9306 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
9307 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9308 private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
9309 private static MBThread _nullMBThread = new MBThreadImpl() {
9310 @Override
9311 public Object clone() {
9312 return this;
9313 }
9314
9315 @Override
9316 public CacheModel<MBThread> toCacheModel() {
9317 return _nullMBThreadCacheModel;
9318 }
9319 };
9320
9321 private static CacheModel<MBThread> _nullMBThreadCacheModel = new CacheModel<MBThread>() {
9322 public MBThread toEntityModel() {
9323 return _nullMBThread;
9324 }
9325 };
9326 }