Search in sources :

Example 1 with WikiNode

use of com.liferay.portlet.wiki.model.WikiNode in project liferay-ide by liferay.

the class WikiNodePersistenceImpl method getByUuid_PrevAndNext.

protected WikiNode getByUuid_PrevAndNext(Session session, WikiNode wikiNode, String uuid, OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }
    query.append(_SQL_SELECT_WIKINODE_WHERE);
    boolean bindUuid = false;
    if (uuid == null) {
        query.append(_FINDER_COLUMN_UUID_UUID_1);
    } else if (uuid.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_UUID_UUID_3);
    } else {
        bindUuid = true;
        query.append(_FINDER_COLUMN_UUID_UUID_2);
    }
    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }
        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);
            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }
        query.append(ORDER_BY_CLAUSE);
        String[] orderByFields = orderByComparator.getOrderByFields();
        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);
            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
    }
    String sql = query.toString();
    Query q = session.createQuery(sql);
    q.setFirstResult(0);
    q.setMaxResults(2);
    QueryPos qPos = QueryPos.getInstance(q);
    if (bindUuid) {
        qPos.add(uuid);
    }
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<WikiNode> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) WikiNode(com.liferay.portlet.wiki.model.WikiNode) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 2 with WikiNode

use of com.liferay.portlet.wiki.model.WikiNode in project liferay-ide by liferay.

the class WikiNodePersistenceImpl method findByCompanyId_Last.

/**
 * Returns the last wiki node in the ordered set where companyId = &#63;.
 *
 * @param companyId the company ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching wiki node
 * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public WikiNode findByCompanyId_Last(long companyId, OrderByComparator orderByComparator) throws NoSuchNodeException, SystemException {
    WikiNode wikiNode = fetchByCompanyId_Last(companyId, orderByComparator);
    if (wikiNode != null) {
        return wikiNode;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("companyId=");
    msg.append(companyId);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchNodeException(msg.toString());
}
Also used : WikiNode(com.liferay.portlet.wiki.model.WikiNode) NoSuchNodeException(com.liferay.portlet.wiki.NoSuchNodeException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 3 with WikiNode

use of com.liferay.portlet.wiki.model.WikiNode in project liferay-ide by liferay.

the class WikiNodePersistenceImpl method getByCompanyId_PrevAndNext.

protected WikiNode getByCompanyId_PrevAndNext(Session session, WikiNode wikiNode, long companyId, OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }
    query.append(_SQL_SELECT_WIKINODE_WHERE);
    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }
        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);
            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }
        query.append(ORDER_BY_CLAUSE);
        String[] orderByFields = orderByComparator.getOrderByFields();
        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);
            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(WikiNodeModelImpl.ORDER_BY_JPQL);
    }
    String sql = query.toString();
    Query q = session.createQuery(sql);
    q.setFirstResult(0);
    q.setMaxResults(2);
    QueryPos qPos = QueryPos.getInstance(q);
    qPos.add(companyId);
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(wikiNode);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<WikiNode> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) WikiNode(com.liferay.portlet.wiki.model.WikiNode) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 4 with WikiNode

use of com.liferay.portlet.wiki.model.WikiNode in project liferay-ide by liferay.

the class WikiNodePersistenceImpl method findByG_N.

/**
 * Returns the wiki node where groupId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.wiki.NoSuchNodeException} if it could not be found.
 *
 * @param groupId the group ID
 * @param name the name
 * @return the matching wiki node
 * @throws com.liferay.portlet.wiki.NoSuchNodeException if a matching wiki node could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public WikiNode findByG_N(long groupId, String name) throws NoSuchNodeException, SystemException {
    WikiNode wikiNode = fetchByG_N(groupId, name);
    if (wikiNode == null) {
        StringBundler msg = new StringBundler(6);
        msg.append(_NO_SUCH_ENTITY_WITH_KEY);
        msg.append("groupId=");
        msg.append(groupId);
        msg.append(", name=");
        msg.append(name);
        msg.append(StringPool.CLOSE_CURLY_BRACE);
        if (_log.isWarnEnabled()) {
            _log.warn(msg.toString());
        }
        throw new NoSuchNodeException(msg.toString());
    }
    return wikiNode;
}
Also used : WikiNode(com.liferay.portlet.wiki.model.WikiNode) NoSuchNodeException(com.liferay.portlet.wiki.NoSuchNodeException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 5 with WikiNode

use of com.liferay.portlet.wiki.model.WikiNode in project liferay-ide by liferay.

the class WikiNodePersistenceImpl method fetchByG_N.

/**
 * Returns the wiki node where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param groupId the group ID
 * @param name the name
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching wiki node, or <code>null</code> if a matching wiki node could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public WikiNode fetchByG_N(long groupId, String name, boolean retrieveFromCache) throws SystemException {
    Object[] finderArgs = new Object[] { groupId, name };
    Object result = null;
    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N, finderArgs, this);
    }
    if (result instanceof WikiNode) {
        WikiNode wikiNode = (WikiNode) result;
        if ((groupId != wikiNode.getGroupId()) || !Validator.equals(name, wikiNode.getName())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(4);
        query.append(_SQL_SELECT_WIKINODE_WHERE);
        query.append(_FINDER_COLUMN_G_N_GROUPID_2);
        boolean bindName = false;
        if (name == null) {
            query.append(_FINDER_COLUMN_G_N_NAME_1);
        } else if (name.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_G_N_NAME_3);
        } else {
            bindName = true;
            query.append(_FINDER_COLUMN_G_N_NAME_2);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(groupId);
            if (bindName) {
                qPos.add(name);
            }
            List<WikiNode> list = q.list();
            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, finderArgs, list);
            } else {
                WikiNode wikiNode = list.get(0);
                result = wikiNode;
                cacheResult(wikiNode);
                if ((wikiNode.getGroupId() != groupId) || (wikiNode.getName() == null) || !wikiNode.getName().equals(name)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, finderArgs, wikiNode);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (WikiNode) result;
    }
}
Also used : SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) WikiNode(com.liferay.portlet.wiki.model.WikiNode) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchNodeException(com.liferay.portlet.wiki.NoSuchNodeException) Session(com.liferay.portal.kernel.dao.orm.Session)

Aggregations

WikiNode (com.liferay.portlet.wiki.model.WikiNode)45 NoSuchNodeException (com.liferay.portlet.wiki.NoSuchNodeException)35 StringBundler (com.liferay.portal.kernel.util.StringBundler)33 Session (com.liferay.portal.kernel.dao.orm.Session)21 SystemException (com.liferay.portal.kernel.exception.SystemException)21 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)19 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)18 Query (com.liferay.portal.kernel.dao.orm.Query)15 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)11 WikiNodeImpl (com.liferay.portlet.wiki.model.impl.WikiNodeImpl)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)7