Search in sources :

Example 96 with FinderPath

use of com.liferay.portal.kernel.dao.orm.FinderPath in project liferay-ide by liferay.

the class KBTemplatePersistenceImpl method findByGroupId.

/**
 * Returns an ordered range of all the k b templates where groupId = ?.
 *
 * <p>
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.knowledgebase.model.impl.KBTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param start the lower bound of the range of k b templates
 * @param end the upper bound of the range of k b templates (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b templates
 * @throws SystemException if a system exception occurred
 */
@Override
public List<KBTemplate> findByGroupId(long groupId, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
        finderArgs = new Object[] { groupId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
        finderArgs = new Object[] { groupId, start, end, orderByComparator };
    }
    List<KBTemplate> list = (List<KBTemplate>) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if ((list != null) && !list.isEmpty()) {
        for (KBTemplate kbTemplate : list) {
            if ((groupId != kbTemplate.getGroupId())) {
                list = null;
                break;
            }
        }
    }
    if (list == null) {
        StringBundler query = null;
        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(3);
        }
        query.append(_SQL_SELECT_KBTEMPLATE_WHERE);
        query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(KBTemplateModelImpl.ORDER_BY_JPQL);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(groupId);
            if (!pagination) {
                list = (List<KBTemplate>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = new UnmodifiableList<KBTemplate>(list);
            } else {
                list = (List<KBTemplate>) QueryUtil.list(q, getDialect(), start, end);
            }
            cacheResult(list);
            FinderCacheUtil.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) KBTemplate(com.liferay.knowledgebase.model.KBTemplate) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchTemplateException(com.liferay.knowledgebase.NoSuchTemplateException) SystemException(com.liferay.portal.kernel.exception.SystemException) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 97 with FinderPath

use of com.liferay.portal.kernel.dao.orm.FinderPath in project liferay-ide by liferay.

the class KBTemplatePersistenceImpl method countByUuid.

/**
 * Returns the number of k b templates where uuid = &#63;.
 *
 * @param uuid the uuid
 * @return the number of matching k b templates
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByUuid(String uuid) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
    Object[] finderArgs = new Object[] { uuid };
    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(2);
        query.append(_SQL_COUNT_KBTEMPLATE_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);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            if (bindUuid) {
                qPos.add(uuid);
            }
            count = (Long) q.uniqueResult();
            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return count.intValue();
}
Also used : SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchTemplateException(com.liferay.knowledgebase.NoSuchTemplateException) SystemException(com.liferay.portal.kernel.exception.SystemException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 98 with FinderPath

use of com.liferay.portal.kernel.dao.orm.FinderPath in project liferay-ide by liferay.

the class KBTemplatePersistenceImpl method countByUUID_G.

/**
 * Returns the number of k b templates where uuid = &#63; and groupId = &#63;.
 *
 * @param uuid the uuid
 * @param groupId the group ID
 * @return the number of matching k b templates
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByUUID_G(String uuid, long groupId) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
    Object[] finderArgs = new Object[] { uuid, groupId };
    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(3);
        query.append(_SQL_COUNT_KBTEMPLATE_WHERE);
        boolean bindUuid = false;
        if (uuid == null) {
            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
        } else if (uuid.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
        } else {
            bindUuid = true;
            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
        }
        query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            if (bindUuid) {
                qPos.add(uuid);
            }
            qPos.add(groupId);
            count = (Long) q.uniqueResult();
            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return count.intValue();
}
Also used : SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchTemplateException(com.liferay.knowledgebase.NoSuchTemplateException) SystemException(com.liferay.portal.kernel.exception.SystemException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 99 with FinderPath

use of com.liferay.portal.kernel.dao.orm.FinderPath in project liferay-ide by liferay.

the class OAuthTokenPersistenceImpl method countByU_G_S_M_T.

/**
 * Returns the number of o auth tokens where userId = &#63; and gadgetKey = &#63; and serviceName = &#63; and moduleId = &#63; and tokenName = &#63;.
 *
 * @param userId the user ID
 * @param gadgetKey the gadget key
 * @param serviceName the service name
 * @param moduleId the module ID
 * @param tokenName the token name
 * @return the number of matching o auth tokens
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByU_G_S_M_T(long userId, String gadgetKey, String serviceName, long moduleId, String tokenName) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_G_S_M_T;
    Object[] finderArgs = new Object[] { userId, gadgetKey, serviceName, moduleId, tokenName };
    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(6);
        query.append(_SQL_COUNT_OAUTHTOKEN_WHERE);
        query.append(_FINDER_COLUMN_U_G_S_M_T_USERID_2);
        boolean bindGadgetKey = false;
        if (gadgetKey == null) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_GADGETKEY_1);
        } else if (gadgetKey.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_GADGETKEY_3);
        } else {
            bindGadgetKey = true;
            query.append(_FINDER_COLUMN_U_G_S_M_T_GADGETKEY_2);
        }
        boolean bindServiceName = false;
        if (serviceName == null) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_SERVICENAME_1);
        } else if (serviceName.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_SERVICENAME_3);
        } else {
            bindServiceName = true;
            query.append(_FINDER_COLUMN_U_G_S_M_T_SERVICENAME_2);
        }
        query.append(_FINDER_COLUMN_U_G_S_M_T_MODULEID_2);
        boolean bindTokenName = false;
        if (tokenName == null) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_TOKENNAME_1);
        } else if (tokenName.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_TOKENNAME_3);
        } else {
            bindTokenName = true;
            query.append(_FINDER_COLUMN_U_G_S_M_T_TOKENNAME_2);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(userId);
            if (bindGadgetKey) {
                qPos.add(gadgetKey);
            }
            if (bindServiceName) {
                qPos.add(serviceName);
            }
            qPos.add(moduleId);
            if (bindTokenName) {
                qPos.add(tokenName);
            }
            count = (Long) q.uniqueResult();
            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return count.intValue();
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthTokenException(com.liferay.opensocial.NoSuchOAuthTokenException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 100 with FinderPath

use of com.liferay.portal.kernel.dao.orm.FinderPath in project liferay-ide by liferay.

the class GadgetPersistenceImpl method countByC_U.

/**
 * Returns the number of gadgets where companyId = &#63; and url = &#63;.
 *
 * @param companyId the company ID
 * @param url the url
 * @return the number of matching gadgets
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByC_U(long companyId, String url) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U;
    Object[] finderArgs = new Object[] { companyId, url };
    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(3);
        query.append(_SQL_COUNT_GADGET_WHERE);
        query.append(_FINDER_COLUMN_C_U_COMPANYID_2);
        boolean bindUrl = false;
        if (url == null) {
            query.append(_FINDER_COLUMN_C_U_URL_1);
        } else if (url.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_U_URL_3);
        } else {
            bindUrl = true;
            query.append(_FINDER_COLUMN_C_U_URL_2);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(companyId);
            if (bindUrl) {
                qPos.add(url);
            }
            count = (Long) q.uniqueResult();
            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return count.intValue();
}
Also used : SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchGadgetException(com.liferay.opensocial.NoSuchGadgetException) Session(com.liferay.portal.kernel.dao.orm.Session)

Aggregations

FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)214 Query (com.liferay.portal.kernel.dao.orm.Query)214 Session (com.liferay.portal.kernel.dao.orm.Session)214 StringBundler (com.liferay.portal.kernel.util.StringBundler)214 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)197 SystemException (com.liferay.portal.kernel.exception.SystemException)191 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)165 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)93 ArrayList (java.util.ArrayList)93 List (java.util.List)93 NoSuchArticleException (com.liferay.knowledgebase.NoSuchArticleException)59 KBArticle (com.liferay.knowledgebase.model.KBArticle)29 NoSuchSongException (org.liferay.jukebox.NoSuchSongException)25 NoSuchAlbumException (org.liferay.jukebox.NoSuchAlbumException)22 NoSuchCommentException (com.liferay.knowledgebase.NoSuchCommentException)18 NoSuchArtistException (org.liferay.jukebox.NoSuchArtistException)18 NoSuchNodeException (com.liferay.portlet.wiki.NoSuchNodeException)15 Song (org.liferay.jukebox.model.Song)12 Album (org.liferay.jukebox.model.Album)11 NoSuchFolderException (com.liferay.knowledgebase.NoSuchFolderException)10