Exemple #1
0
  protected int doCountByG_C(
      long groupId, long categoryId, QueryDefinition queryDefinition, boolean inlineSQLHelper)
      throws SystemException {

    if (!inlineSQLHelper || !InlineSQLHelperUtil.isEnabled(groupId)) {
      if (queryDefinition.isExcludeStatus()) {
        return MBThreadUtil.countByG_C_NotS(groupId, categoryId, queryDefinition.getStatus());
      } else {
        if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {

          return MBThreadUtil.countByG_C_S(groupId, categoryId, queryDefinition.getStatus());
        } else {
          return MBThreadUtil.countByG_C(groupId, categoryId);
        }
      }
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_G_C);

      sql = updateSQL(sql, queryDefinition);

      sql =
          InlineSQLHelperUtil.replacePermissionCheck(
              sql, MBMessage.class.getName(), "MBThread.rootMessageId", groupId);

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(categoryId);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        qPos.add(queryDefinition.getStatus());
      }

      Iterator<Long> itr = q.iterate();

      if (itr.hasNext()) {
        Long count = itr.next();

        if (count != null) {
          return count.intValue();
        }
      }

      return 0;
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }
  }
Exemple #2
0
  @Override
  public List<MBThread> filterFindByG_C(long groupId, long categoryId, int start, int end)
      throws SystemException {

    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
      return MBThreadUtil.findByG_C(groupId, categoryId, start, end);
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_G_C);

      sql =
          InlineSQLHelperUtil.replacePermissionCheck(
              sql, MBMessage.class.getName(), "MBThread.rootMessageId", groupId);

      SQLQuery q = session.createSQLQuery(sql);

      q.addEntity("MBThread", MBThreadImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(categoryId);

      return (List<MBThread>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
Exemple #3
0
  @Override
  public int filterCountByG_C(long groupId, long categoryId) throws SystemException {

    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
      return MBThreadUtil.countByG_C(groupId, categoryId);
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_G_C);

      sql =
          InlineSQLHelperUtil.replacePermissionCheck(
              sql, MBMessage.class.getName(), "MBThread.rootMessageId", groupId);

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(categoryId);

      Iterator<Long> itr = q.iterate();

      if (itr.hasNext()) {
        Long count = itr.next();

        if (count != null) {
          return count.intValue();
        }
      }

      return 0;
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }
  }
/** @generated */
@RunWith(LiferayIntegrationJUnitTestRunner.class)
public class MBThreadPersistenceTest {
  @ClassRule
  public static TransactionalTestRule transactionalTestRule =
      new TransactionalTestRule(Propagation.REQUIRED);

  @BeforeClass
  public static void setupClass() throws TemplateException {
    try {
      DBUpgrader.upgrade();
    } catch (Exception e) {
      _log.error(e, e);
    }

    TemplateManagerUtil.init();
  }

  @Before
  public void setUp() {
    _modelListeners = _persistence.getListeners();

    for (ModelListener<MBThread> modelListener : _modelListeners) {
      _persistence.unregisterListener(modelListener);
    }
  }

  @After
  public void tearDown() throws Exception {
    Iterator<MBThread> iterator = _mbThreads.iterator();

    while (iterator.hasNext()) {
      _persistence.remove(iterator.next());

      iterator.remove();
    }

    for (ModelListener<MBThread> modelListener : _modelListeners) {
      _persistence.registerListener(modelListener);
    }
  }

  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBThread mbThread = _persistence.create(pk);

    Assert.assertNotNull(mbThread);

    Assert.assertEquals(mbThread.getPrimaryKey(), pk);
  }

  @Test
  public void testRemove() throws Exception {
    MBThread newMBThread = addMBThread();

    _persistence.remove(newMBThread);

    MBThread existingMBThread = _persistence.fetchByPrimaryKey(newMBThread.getPrimaryKey());

    Assert.assertNull(existingMBThread);
  }

  @Test
  public void testUpdateNew() throws Exception {
    addMBThread();
  }

  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBThread newMBThread = _persistence.create(pk);

    newMBThread.setUuid(RandomTestUtil.randomString());

    newMBThread.setGroupId(RandomTestUtil.nextLong());

    newMBThread.setCompanyId(RandomTestUtil.nextLong());

    newMBThread.setUserId(RandomTestUtil.nextLong());

    newMBThread.setUserName(RandomTestUtil.randomString());

    newMBThread.setCreateDate(RandomTestUtil.nextDate());

    newMBThread.setModifiedDate(RandomTestUtil.nextDate());

    newMBThread.setCategoryId(RandomTestUtil.nextLong());

    newMBThread.setRootMessageId(RandomTestUtil.nextLong());

    newMBThread.setRootMessageUserId(RandomTestUtil.nextLong());

    newMBThread.setMessageCount(RandomTestUtil.nextInt());

    newMBThread.setViewCount(RandomTestUtil.nextInt());

    newMBThread.setLastPostByUserId(RandomTestUtil.nextLong());

    newMBThread.setLastPostDate(RandomTestUtil.nextDate());

    newMBThread.setPriority(RandomTestUtil.nextDouble());

    newMBThread.setQuestion(RandomTestUtil.randomBoolean());

    newMBThread.setStatus(RandomTestUtil.nextInt());

    newMBThread.setStatusByUserId(RandomTestUtil.nextLong());

    newMBThread.setStatusByUserName(RandomTestUtil.randomString());

    newMBThread.setStatusDate(RandomTestUtil.nextDate());

    _mbThreads.add(_persistence.update(newMBThread));

    MBThread existingMBThread = _persistence.findByPrimaryKey(newMBThread.getPrimaryKey());

    Assert.assertEquals(existingMBThread.getUuid(), newMBThread.getUuid());
    Assert.assertEquals(existingMBThread.getThreadId(), newMBThread.getThreadId());
    Assert.assertEquals(existingMBThread.getGroupId(), newMBThread.getGroupId());
    Assert.assertEquals(existingMBThread.getCompanyId(), newMBThread.getCompanyId());
    Assert.assertEquals(existingMBThread.getUserId(), newMBThread.getUserId());
    Assert.assertEquals(existingMBThread.getUserName(), newMBThread.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBThread.getCreateDate()),
        Time.getShortTimestamp(newMBThread.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBThread.getModifiedDate()),
        Time.getShortTimestamp(newMBThread.getModifiedDate()));
    Assert.assertEquals(existingMBThread.getCategoryId(), newMBThread.getCategoryId());
    Assert.assertEquals(existingMBThread.getRootMessageId(), newMBThread.getRootMessageId());
    Assert.assertEquals(
        existingMBThread.getRootMessageUserId(), newMBThread.getRootMessageUserId());
    Assert.assertEquals(existingMBThread.getMessageCount(), newMBThread.getMessageCount());
    Assert.assertEquals(existingMBThread.getViewCount(), newMBThread.getViewCount());
    Assert.assertEquals(existingMBThread.getLastPostByUserId(), newMBThread.getLastPostByUserId());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBThread.getLastPostDate()),
        Time.getShortTimestamp(newMBThread.getLastPostDate()));
    AssertUtils.assertEquals(existingMBThread.getPriority(), newMBThread.getPriority());
    Assert.assertEquals(existingMBThread.getQuestion(), newMBThread.getQuestion());
    Assert.assertEquals(existingMBThread.getStatus(), newMBThread.getStatus());
    Assert.assertEquals(existingMBThread.getStatusByUserId(), newMBThread.getStatusByUserId());
    Assert.assertEquals(existingMBThread.getStatusByUserName(), newMBThread.getStatusByUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBThread.getStatusDate()),
        Time.getShortTimestamp(newMBThread.getStatusDate()));
  }

  @Test
  public void testCountByUuid() {
    try {
      _persistence.countByUuid(StringPool.BLANK);

      _persistence.countByUuid(StringPool.NULL);

      _persistence.countByUuid((String) null);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByUUID_G() {
    try {
      _persistence.countByUUID_G(StringPool.BLANK, RandomTestUtil.nextLong());

      _persistence.countByUUID_G(StringPool.NULL, 0L);

      _persistence.countByUUID_G((String) null, 0L);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByUuid_C() {
    try {
      _persistence.countByUuid_C(StringPool.BLANK, RandomTestUtil.nextLong());

      _persistence.countByUuid_C(StringPool.NULL, 0L);

      _persistence.countByUuid_C((String) null, 0L);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByGroupId() {
    try {
      _persistence.countByGroupId(RandomTestUtil.nextLong());

      _persistence.countByGroupId(0L);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByRootMessageId() {
    try {
      _persistence.countByRootMessageId(RandomTestUtil.nextLong());

      _persistence.countByRootMessageId(0L);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_C() {
    try {
      _persistence.countByG_C(RandomTestUtil.nextLong(), RandomTestUtil.nextLong());

      _persistence.countByG_C(0L, 0L);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_CArrayable() {
    try {
      _persistence.countByG_C(
          RandomTestUtil.nextLong(), new long[] {RandomTestUtil.nextLong(), 0L});
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_NotC() {
    try {
      _persistence.countByG_NotC(RandomTestUtil.nextLong(), RandomTestUtil.nextLong());

      _persistence.countByG_NotC(0L, 0L);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_S() {
    try {
      _persistence.countByG_S(RandomTestUtil.nextLong(), RandomTestUtil.nextInt());

      _persistence.countByG_S(0L, 0);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByC_P() {
    try {
      _persistence.countByC_P(RandomTestUtil.nextLong(), RandomTestUtil.nextDouble());

      _persistence.countByC_P(0L, 0D);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByL_P() {
    try {
      _persistence.countByL_P(RandomTestUtil.nextDate(), RandomTestUtil.nextDouble());

      _persistence.countByL_P(RandomTestUtil.nextDate(), 0D);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_C_L() {
    try {
      _persistence.countByG_C_L(
          RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), RandomTestUtil.nextDate());

      _persistence.countByG_C_L(0L, 0L, RandomTestUtil.nextDate());
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_C_S() {
    try {
      _persistence.countByG_C_S(
          RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), RandomTestUtil.nextInt());

      _persistence.countByG_C_S(0L, 0L, 0);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_C_SArrayable() {
    try {
      _persistence.countByG_C_S(
          RandomTestUtil.nextLong(),
          new long[] {RandomTestUtil.nextLong(), 0L},
          RandomTestUtil.nextInt());
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_C_NotS() {
    try {
      _persistence.countByG_C_NotS(
          RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), RandomTestUtil.nextInt());

      _persistence.countByG_C_NotS(0L, 0L, 0);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_C_NotSArrayable() {
    try {
      _persistence.countByG_C_NotS(
          RandomTestUtil.nextLong(),
          new long[] {RandomTestUtil.nextLong(), 0L},
          RandomTestUtil.nextInt());
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_NotC_S() {
    try {
      _persistence.countByG_NotC_S(
          RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), RandomTestUtil.nextInt());

      _persistence.countByG_NotC_S(0L, 0L, 0);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testCountByG_NotC_NotS() {
    try {
      _persistence.countByG_NotC_NotS(
          RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), RandomTestUtil.nextInt());

      _persistence.countByG_NotC_NotS(0L, 0L, 0);
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testFindByPrimaryKeyExisting() throws Exception {
    MBThread newMBThread = addMBThread();

    MBThread existingMBThread = _persistence.findByPrimaryKey(newMBThread.getPrimaryKey());

    Assert.assertEquals(existingMBThread, newMBThread);
  }

  @Test
  public void testFindByPrimaryKeyMissing() throws Exception {
    long pk = RandomTestUtil.nextLong();

    try {
      _persistence.findByPrimaryKey(pk);

      Assert.fail("Missing entity did not throw NoSuchThreadException");
    } catch (NoSuchThreadException nsee) {
    }
  }

  @Test
  public void testFindAll() throws Exception {
    try {
      _persistence.findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  @Test
  public void testFilterFindByGroupId() throws Exception {
    try {
      _persistence.filterFindByGroupId(
          0, QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }

  protected OrderByComparator<MBThread> getOrderByComparator() {
    return OrderByComparatorFactoryUtil.create(
        "MBThread",
        "uuid",
        true,
        "threadId",
        true,
        "groupId",
        true,
        "companyId",
        true,
        "userId",
        true,
        "userName",
        true,
        "createDate",
        true,
        "modifiedDate",
        true,
        "categoryId",
        true,
        "rootMessageId",
        true,
        "rootMessageUserId",
        true,
        "messageCount",
        true,
        "viewCount",
        true,
        "lastPostByUserId",
        true,
        "lastPostDate",
        true,
        "priority",
        true,
        "question",
        true,
        "status",
        true,
        "statusByUserId",
        true,
        "statusByUserName",
        true,
        "statusDate",
        true);
  }

  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    MBThread newMBThread = addMBThread();

    MBThread existingMBThread = _persistence.fetchByPrimaryKey(newMBThread.getPrimaryKey());

    Assert.assertEquals(existingMBThread, newMBThread);
  }

  @Test
  public void testFetchByPrimaryKeyMissing() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBThread missingMBThread = _persistence.fetchByPrimaryKey(pk);

    Assert.assertNull(missingMBThread);
  }

  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    MBThread newMBThread1 = addMBThread();
    MBThread newMBThread2 = addMBThread();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newMBThread1.getPrimaryKey());
    primaryKeys.add(newMBThread2.getPrimaryKey());

    Map<Serializable, MBThread> mbThreads = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, mbThreads.size());
    Assert.assertEquals(newMBThread1, mbThreads.get(newMBThread1.getPrimaryKey()));
    Assert.assertEquals(newMBThread2, mbThreads.get(newMBThread2.getPrimaryKey()));
  }

  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
      throws Exception {
    long pk1 = RandomTestUtil.nextLong();

    long pk2 = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(pk1);
    primaryKeys.add(pk2);

    Map<Serializable, MBThread> mbThreads = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertTrue(mbThreads.isEmpty());
  }

  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    MBThread newMBThread = addMBThread();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newMBThread.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, MBThread> mbThreads = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, mbThreads.size());
    Assert.assertEquals(newMBThread, mbThreads.get(newMBThread.getPrimaryKey()));
  }

  @Test
  public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    Map<Serializable, MBThread> mbThreads = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertTrue(mbThreads.isEmpty());
  }

  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    MBThread newMBThread = addMBThread();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newMBThread.getPrimaryKey());

    Map<Serializable, MBThread> mbThreads = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, mbThreads.size());
    Assert.assertEquals(newMBThread, mbThreads.get(newMBThread.getPrimaryKey()));
  }

  @Test
  public void testActionableDynamicQuery() throws Exception {
    final IntegerWrapper count = new IntegerWrapper();

    ActionableDynamicQuery actionableDynamicQuery =
        MBThreadLocalServiceUtil.getActionableDynamicQuery();

    actionableDynamicQuery.setPerformActionMethod(
        new ActionableDynamicQuery.PerformActionMethod() {
          @Override
          public void performAction(Object object) {
            MBThread mbThread = (MBThread) object;

            Assert.assertNotNull(mbThread);

            count.increment();
          }
        });

    actionableDynamicQuery.performActions();

    Assert.assertEquals(count.getValue(), _persistence.countAll());
  }

  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    MBThread newMBThread = addMBThread();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(MBThread.class, MBThread.class.getClassLoader());

    dynamicQuery.add(RestrictionsFactoryUtil.eq("threadId", newMBThread.getThreadId()));

    List<MBThread> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    MBThread existingMBThread = result.get(0);

    Assert.assertEquals(existingMBThread, newMBThread);
  }

  @Test
  public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(MBThread.class, MBThread.class.getClassLoader());

    dynamicQuery.add(RestrictionsFactoryUtil.eq("threadId", RandomTestUtil.nextLong()));

    List<MBThread> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(0, result.size());
  }

  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    MBThread newMBThread = addMBThread();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(MBThread.class, MBThread.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("threadId"));

    Object newThreadId = newMBThread.getThreadId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("threadId", new Object[] {newThreadId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingThreadId = result.get(0);

    Assert.assertEquals(existingThreadId, newThreadId);
  }

  @Test
  public void testDynamicQueryByProjectionMissing() throws Exception {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(MBThread.class, MBThread.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("threadId"));

    dynamicQuery.add(
        RestrictionsFactoryUtil.in("threadId", new Object[] {RandomTestUtil.nextLong()}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(0, result.size());
  }

  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    MBThread newMBThread = addMBThread();

    _persistence.clearCache();

    MBThreadModelImpl existingMBThreadModelImpl =
        (MBThreadModelImpl) _persistence.findByPrimaryKey(newMBThread.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingMBThreadModelImpl.getUuid(), existingMBThreadModelImpl.getOriginalUuid()));
    Assert.assertEquals(
        existingMBThreadModelImpl.getGroupId(), existingMBThreadModelImpl.getOriginalGroupId());

    Assert.assertEquals(
        existingMBThreadModelImpl.getRootMessageId(),
        existingMBThreadModelImpl.getOriginalRootMessageId());
  }

  protected MBThread addMBThread() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBThread mbThread = _persistence.create(pk);

    mbThread.setUuid(RandomTestUtil.randomString());

    mbThread.setGroupId(RandomTestUtil.nextLong());

    mbThread.setCompanyId(RandomTestUtil.nextLong());

    mbThread.setUserId(RandomTestUtil.nextLong());

    mbThread.setUserName(RandomTestUtil.randomString());

    mbThread.setCreateDate(RandomTestUtil.nextDate());

    mbThread.setModifiedDate(RandomTestUtil.nextDate());

    mbThread.setCategoryId(RandomTestUtil.nextLong());

    mbThread.setRootMessageId(RandomTestUtil.nextLong());

    mbThread.setRootMessageUserId(RandomTestUtil.nextLong());

    mbThread.setMessageCount(RandomTestUtil.nextInt());

    mbThread.setViewCount(RandomTestUtil.nextInt());

    mbThread.setLastPostByUserId(RandomTestUtil.nextLong());

    mbThread.setLastPostDate(RandomTestUtil.nextDate());

    mbThread.setPriority(RandomTestUtil.nextDouble());

    mbThread.setQuestion(RandomTestUtil.randomBoolean());

    mbThread.setStatus(RandomTestUtil.nextInt());

    mbThread.setStatusByUserId(RandomTestUtil.nextLong());

    mbThread.setStatusByUserName(RandomTestUtil.randomString());

    mbThread.setStatusDate(RandomTestUtil.nextDate());

    _mbThreads.add(_persistence.update(mbThread));

    return mbThread;
  }

  private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceTest.class);
  private List<MBThread> _mbThreads = new ArrayList<MBThread>();
  private ModelListener<MBThread>[] _modelListeners;
  private MBThreadPersistence _persistence = MBThreadUtil.getPersistence();
}
Exemple #5
0
  protected List<MBThread> doFindByG_C(
      long groupId, long categoryId, QueryDefinition queryDefinition, boolean inlineSQLHelper)
      throws SystemException {

    if (!inlineSQLHelper || !InlineSQLHelperUtil.isEnabled(groupId)) {
      if (queryDefinition.isExcludeStatus()) {
        return MBThreadUtil.findByG_C_NotS(
            groupId,
            categoryId,
            queryDefinition.getStatus(),
            queryDefinition.getStart(),
            queryDefinition.getEnd());
      } else {
        if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {

          return MBThreadUtil.findByG_C_S(
              groupId,
              categoryId,
              queryDefinition.getStatus(),
              queryDefinition.getStart(),
              queryDefinition.getEnd());
        } else {
          return MBThreadUtil.findByG_C(
              groupId, categoryId, queryDefinition.getStart(), queryDefinition.getEnd());
        }
      }
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_G_C);

      sql = updateSQL(sql, queryDefinition);

      sql =
          InlineSQLHelperUtil.replacePermissionCheck(
              sql, MBMessage.class.getName(), "MBThread.rootMessageId", groupId);

      SQLQuery q = session.createSQLQuery(sql);

      q.addEntity("MBThread", MBThreadImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(categoryId);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        qPos.add(queryDefinition.getStatus());
      }

      return (List<MBThread>)
          QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd());
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }