Example usage for com.liferay.portal.kernel.dao.orm QueryDefinition getOwnerUserId

List of usage examples for com.liferay.portal.kernel.dao.orm QueryDefinition getOwnerUserId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.orm QueryDefinition getOwnerUserId.

Prototype

public long getOwnerUserId() 

Source Link

Usage

From source file:com.liferay.journal.service.persistence.impl.JournalArticleFinderImpl.java

License:Open Source License

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

    Session session = null;//from w  ww  .j a  va2  s.c o m

    try {
        session = openSession();

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

        sql = replaceStatusJoin(sql, queryDefinition);

        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 (inlineSQLHelper) {
            sql = InlineSQLHelperUtil.replacePermissionCheck(sql, JournalArticle.class.getName(),
                    "JournalArticle.resourcePrimKey", groupId);
        }

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

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

        if (queryDefinition.getOwnerUserId() > 0) {
            qPos.add(queryDefinition.getOwnerUserId());

            if (queryDefinition.isIncludeOwner()) {
                qPos.add(WorkflowConstants.STATUS_IN_TRASH);
            }
        }

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

        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 new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.journal.service.persistence.impl.JournalArticleFinderImpl.java

License:Open Source License

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

    Session session = null;/*from   w w  w .  j  ava  2  s  .  c om*/

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(getClass(), 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 (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 (queryDefinition.getOwnerUserId() > 0) {
            qPos.add(queryDefinition.getOwnerUserId());

            if (queryDefinition.isIncludeOwner()) {
                qPos.add(WorkflowConstants.STATUS_IN_TRASH);
            }
        }

        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);
    }
}

From source file:com.liferay.journal.service.persistence.impl.JournalFolderFinderImpl.java

License:Open Source License

protected int doCountF_A_ByG_F(long groupId, long folderId, QueryDefinition<?> queryDefinition,
        boolean inlineSQLHelper) {

    Session session = null;//  w  ww  . ja v a 2s .c om

    try {
        session = openSession();

        StringBundler sb = new StringBundler(5);

        sb.append(StringPool.OPEN_PARENTHESIS);
        sb.append(getFoldersSQL(COUNT_F_BY_G_F, groupId, queryDefinition, inlineSQLHelper));
        sb.append(") UNION ALL (");
        sb.append(getArticlesSQL(COUNT_A_BY_G_U_F, groupId, queryDefinition, inlineSQLHelper));
        sb.append(StringPool.CLOSE_PARENTHESIS);

        String sql = updateSQL(sb.toString(), folderId);

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

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

        if (folderId >= 0) {
            qPos.add(folderId);
        }

        qPos.add(groupId);

        if (queryDefinition.getOwnerUserId() > 0) {
            qPos.add(queryDefinition.getOwnerUserId());
            qPos.add(WorkflowConstants.STATUS_IN_TRASH);
        }

        qPos.add(queryDefinition.getStatus());

        if (folderId >= 0) {
            qPos.add(folderId);
        }

        int count = 0;

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

        while (itr.hasNext()) {
            Long l = itr.next();

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

        return count;
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.journal.service.persistence.impl.JournalFolderFinderImpl.java

License:Open Source License

protected List<Object> doFindF_A_ByG_F(long groupId, long folderId, QueryDefinition<?> queryDefinition,
        boolean inlineSQLHelper) {

    Session session = null;/*from  w w w.j a v  a2s  .  com*/

    try {
        session = openSession();

        StringBundler sb = new StringBundler(5);

        sb.append(StringPool.OPEN_PARENTHESIS);
        sb.append(getFoldersSQL(FIND_F_BY_G_F, groupId, queryDefinition, inlineSQLHelper));
        sb.append(") UNION ALL (");
        sb.append(getArticlesSQL(FIND_A_BY_G_U_F, groupId, queryDefinition, inlineSQLHelper));
        sb.append(StringPool.CLOSE_PARENTHESIS);

        String sql = updateSQL(sb.toString(), folderId);

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

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar("modelFolderId", Type.LONG);
        q.addScalar("modelFolder", Type.LONG);
        q.addScalar("articleId", Type.STRING);
        q.addScalar("version", Type.DOUBLE);

        QueryPos qPos = QueryPos.getInstance(q);

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

        if (folderId >= 0) {
            qPos.add(folderId);
        }

        qPos.add(groupId);

        if (queryDefinition.getOwnerUserId() > 0) {
            qPos.add(queryDefinition.getOwnerUserId());
            qPos.add(WorkflowConstants.STATUS_IN_TRASH);
        }

        qPos.add(queryDefinition.getStatus());

        if (folderId >= 0) {
            qPos.add(folderId);
        }

        List<Object> models = new ArrayList<>();

        Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(),
                queryDefinition.getStart(), queryDefinition.getEnd());

        while (itr.hasNext()) {
            Object[] array = itr.next();

            long curFolderId = (Long) array[0];
            long modelFolder = (Long) array[1];

            Object obj = null;

            if (modelFolder == 1) {
                obj = JournalFolderUtil.findByPrimaryKey(curFolderId);
            } else {
                String articleId = (String) array[2];
                double version = (Double) array[3];

                obj = JournalArticleUtil.findByG_A_V(groupId, articleId, version);
            }

            models.add(obj);
        }

        return models;
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.journal.service.persistence.impl.JournalFolderFinderImpl.java

License:Open Source License

protected List<Object> doFindF_A_ByG_F_L(long groupId, long folderId, Locale locale,
        QueryDefinition<?> queryDefinition, boolean inlineSQLHelper) {

    Session session = null;//from   w  ww .java  2s.c  o  m

    try {
        session = openSession();

        StringBundler sb = new StringBundler(5);

        sb.append(StringPool.OPEN_PARENTHESIS);
        sb.append(getFoldersSQL(FIND_F_BY_G_F_L, groupId, queryDefinition, inlineSQLHelper));
        sb.append(") UNION ALL (");
        sb.append(getArticlesSQL(FIND_A_BY_G_U_F_L, groupId, queryDefinition, inlineSQLHelper));
        sb.append(StringPool.CLOSE_PARENTHESIS);

        String sql = updateSQL(sb.toString(), folderId);

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

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar("modelFolderId", Type.LONG);
        q.addScalar("modelFolder", Type.LONG);
        q.addScalar("articleId", Type.STRING);
        q.addScalar("version", Type.DOUBLE);

        QueryPos qPos = QueryPos.getInstance(q);

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

        if (folderId >= 0) {
            qPos.add(folderId);
        }

        qPos.add(groupId);

        if (queryDefinition.getOwnerUserId() > 0) {
            qPos.add(queryDefinition.getOwnerUserId());
            qPos.add(WorkflowConstants.STATUS_IN_TRASH);
        }

        qPos.add(queryDefinition.getStatus());

        if (folderId >= 0) {
            qPos.add(folderId);
        }

        qPos.add(LocaleUtil.toLanguageId(locale));

        List<Object> models = new ArrayList<>();

        Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.iterate(q, getDialect(),
                queryDefinition.getStart(), queryDefinition.getEnd());

        while (itr.hasNext()) {
            Object[] array = itr.next();

            long curFolderId = (Long) array[0];
            long modelFolder = (Long) array[1];

            Object obj = null;

            if (modelFolder == 1) {
                obj = JournalFolderUtil.findByPrimaryKey(curFolderId);
            } else {
                String articleId = (String) array[2];
                double version = (Double) array[3];

                obj = JournalArticleUtil.findByG_A_V(groupId, articleId, version);
            }

            models.add(obj);
        }

        return models;
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.petra.model.adapter.util.ModelAdapterUtil.java

License:Open Source License

public static <T, V> QueryDefinition<T> adapt(Class<V> clazz, QueryDefinition<V> queryDefinition) {

    if (queryDefinition == null) {
        return null;
    }/*from w w  w .  j av a  2  s.c om*/

    QueryDefinition<T> adaptedQueryDefinition = new QueryDefinition<>(queryDefinition.getStatus(),
            queryDefinition.isExcludeStatus(), queryDefinition.getOwnerUserId(),
            queryDefinition.isIncludeOwner(), queryDefinition.getStart(), queryDefinition.getEnd(),
            adapt(clazz, queryDefinition.getOrderByComparator()));

    adaptedQueryDefinition.setAttributes(queryDefinition.getAttributes());

    return adaptedQueryDefinition;
}

From source file:com.liferay.wiki.service.persistence.impl.WikiPageFinderImpl.java

License:Open Source License

protected int doCountByG_N_H_S(long groupId, long nodeId, boolean head,
        QueryDefinition<WikiPage> queryDefinition, boolean inlineSQLHelper) {

    Session session = null;//from   ww  w.  jav  a  2s .c  o m

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(getClass(), COUNT_BY_G_N_H_S, queryDefinition, "WikiPage");

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

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);
        qPos.add(nodeId);
        qPos.add(head);

        if (queryDefinition.getOwnerUserId() > 0) {
            qPos.add(queryDefinition.getOwnerUserId());

            if (queryDefinition.isIncludeOwner()) {
                qPos.add(WorkflowConstants.STATUS_IN_TRASH);
            }
        }

        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 new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.wiki.service.persistence.impl.WikiPageFinderImpl.java

License:Open Source License

protected List<WikiPage> doFindByG_N_H_S(long groupId, long nodeId, boolean head,
        QueryDefinition<WikiPage> queryDefinition, boolean inlineSQLHelper) {

    Session session = null;// w w w . ja  v  a  2  s  .com

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(getClass(), FIND_BY_G_N_H_S, queryDefinition, "WikiPage");

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

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

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addEntity("WikiPage", WikiPageImpl.class);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);
        qPos.add(nodeId);
        qPos.add(head);

        if (queryDefinition.getOwnerUserId() > 0) {
            qPos.add(queryDefinition.getOwnerUserId());

            if (queryDefinition.isIncludeOwner()) {
                qPos.add(WorkflowConstants.STATUS_IN_TRASH);
            }
        }

        qPos.add(queryDefinition.getStatus());

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