protected List<JournalArticle> doFindByG_F(
      long groupId,
      List<Long> folderIds,
      QueryDefinition<JournalArticle> queryDefinition,
      boolean inlineSQLHelper) {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_G_F, queryDefinition, "JournalArticle");

      sql = replaceStatusJoin(sql, queryDefinition);

      sql =
          CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator("JournalArticle"));

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId);
      }

      sql =
          StringUtil.replace(
              sql, "[$FOLDER_ID$]", getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(queryDefinition.getStatus());

      for (int i = 0; i < folderIds.size(); i++) {
        Long folderId = folderIds.get(i);

        qPos.add(folderId);
      }

      return (List<JournalArticle>)
          QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd());
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  @Override
  public List<BlogsEntry> findByOrganizationIds(
      List<Long> organizationIds, Date displayDate, QueryDefinition<BlogsEntry> queryDefinition) {

    Timestamp displayDate_TS = CalendarUtil.getTimestamp(displayDate);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_ORGANIZATION_IDS);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        if (queryDefinition.isExcludeStatus()) {
          sql = CustomSQLUtil.appendCriteria(sql, "AND (BlogsEntry.status != ?)");
        } else {
          sql = CustomSQLUtil.appendCriteria(sql, "AND (BlogsEntry.status = ?)");
        }
      }

      sql = StringUtil.replace(sql, "[$ORGANIZATION_ID$]", getOrganizationIds(organizationIds));
      sql = CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator());

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity("BlogsEntry", BlogsEntryImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      for (int i = 0; i < organizationIds.size(); i++) {
        Long organizationId = organizationIds.get(i);

        qPos.add(organizationId);
      }

      qPos.add(displayDate_TS);

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

      return (List<BlogsEntry>)
          QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd());
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  protected List<JournalArticle> doFindByC_G_F_C_A_V_T_D_C_S_T_D_R(
      long companyId,
      long groupId,
      List<Long> folderIds,
      long classNameId,
      String[] articleIds,
      Double version,
      String[] titles,
      String[] descriptions,
      String[] contents,
      String[] ddmStructureKeys,
      String[] ddmTemplateKeys,
      Date displayDateGT,
      Date displayDateLT,
      Date reviewDate,
      boolean andOperator,
      QueryDefinition<JournalArticle> queryDefinition,
      boolean inlineSQLHelper) {

    articleIds = CustomSQLUtil.keywords(articleIds, false);
    titles = CustomSQLUtil.keywords(titles);
    descriptions = CustomSQLUtil.keywords(descriptions, false);
    contents = CustomSQLUtil.keywords(contents, false);
    ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
    ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
    Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
    Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
    Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);

    Session session = null;

    try {
      session = openSession();

      String sql =
          CustomSQLUtil.get(FIND_BY_C_G_F_C_A_V_T_D_C_S_T_D_R, queryDefinition, "JournalArticle");

      sql = replaceStatusJoin(sql, queryDefinition);

      if (groupId <= 0) {
        sql = StringUtil.replace(sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
      }

      if (folderIds.isEmpty()) {
        sql = StringUtil.replace(sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
      } else {
        sql =
            StringUtil.replace(
                sql, "[$FOLDER_ID$]", getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
      }

      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.articleId", StringPool.LIKE, false, articleIds);

      if ((version == null) || (version <= 0)) {
        sql =
            StringUtil.replace(
                sql, "(JournalArticle.version = ?) [$AND_OR_CONNECTOR$]", StringPool.BLANK);
      }

      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(JournalArticle.title)", StringPool.LIKE, false, titles);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.description", StringPool.LIKE, false, descriptions);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.content", StringPool.LIKE, false, contents);

      sql = replaceStructureTemplate(sql, ddmStructureKeys, ddmTemplateKeys);

      if (!isNullArray(ddmStructureKeys)) {
        sql =
            CustomSQLUtil.replaceKeywords(
                sql, "JournalArticle.DDMStructureKey", StringPool.LIKE, false, ddmStructureKeys);
      }

      if (!isNullArray(ddmTemplateKeys)) {
        sql =
            CustomSQLUtil.replaceKeywords(
                sql, "JournalArticle.DDMTemplateKey", StringPool.LIKE, false, ddmTemplateKeys);
      }

      sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
      sql =
          CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator("JournalArticle"));

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId);

        sql = StringUtil.replace(sql, "(companyId", "(JournalArticle.companyId");
      }

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(companyId);

      if (groupId > 0) {
        qPos.add(groupId);
      }

      for (long folderId : folderIds) {
        qPos.add(folderId);
      }

      qPos.add(classNameId);
      qPos.add(queryDefinition.getStatus());

      if (!isNullArray(ddmStructureKeys)) {
        qPos.add(ddmStructureKeys, 2);
      }

      if (!isNullArray(ddmTemplateKeys)) {
        qPos.add(ddmTemplateKeys, 2);
      }

      qPos.add(articleIds, 2);

      if ((version != null) && (version > 0)) {
        qPos.add(version);
      }

      qPos.add(titles, 2);
      qPos.add(descriptions, 2);
      qPos.add(contents, 2);
      qPos.add(displayDateGT_TS);
      qPos.add(displayDateGT_TS);
      qPos.add(displayDateLT_TS);
      qPos.add(displayDateLT_TS);
      qPos.add(reviewDate_TS);
      qPos.add(reviewDate_TS);

      return (List<JournalArticle>)
          QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd());
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  protected List<JournalArticle> doFindByG_U_F_C(
      long groupId,
      long userId,
      List<Long> folderIds,
      long classNameId,
      QueryDefinition<JournalArticle> queryDefinition,
      boolean inlineSQLHelper) {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_G_U_F_C, queryDefinition, "JournalArticle");

      sql = replaceStatusJoin(sql, queryDefinition);

      sql =
          CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator("JournalArticle"));

      if (folderIds.isEmpty()) {
        sql = StringUtil.replace(sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
      } else {
        sql =
            StringUtil.replace(
                sql, "[$FOLDER_ID$]", getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
      }

      if (userId <= 0) {
        sql = StringUtil.replace(sql, "(JournalArticle.userId = ?) AND", StringPool.BLANK);
      }

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId);
      }

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(classNameId);

      if (userId > 0) {
        qPos.add(userId);
      }

      for (long folderId : folderIds) {
        qPos.add(folderId);
      }

      qPos.add(queryDefinition.getStatus());

      return (List<JournalArticle>)
          QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd());
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  protected List<JournalArticle> doFindByG_C_S(
      long groupId,
      long classNameId,
      String ddmStructureKey,
      QueryDefinition<JournalArticle> queryDefinition,
      boolean inlineSQLHelper) {

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_G_C_S, queryDefinition, "JournalArticle");

      sql = replaceStatusJoin(sql, queryDefinition);

      sql =
          CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator("JournalArticle"));

      if (groupId <= 0) {
        sql = StringUtil.replace(sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
      }

      if (ddmStructureKey.equals(String.valueOf(JournalArticleConstants.CLASSNAME_ID_DEFAULT))) {

        sql =
            StringUtil.replace(
                sql,
                "(JournalArticle.DDMStructureKey = ?)",
                "((JournalArticle.DDMStructureKey = ?) OR "
                    + "(JournalArticle.DDMStructureKey = '') OR"
                    + "(JournalArticle.DDMStructureKey IS NULL))");
      }

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId);
      }

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      if (groupId > 0) {
        qPos.add(groupId);
      }

      qPos.add(classNameId);
      qPos.add(ddmStructureKey);
      qPos.add(queryDefinition.getStatus());

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