Search in sources :

Example 41 with QueryPos

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

the class ArtistPersistenceImpl method countByU_G.

/**
 * Returns the number of artists where userId = ? and groupId = ?.
 *
 * @param userId the user ID
 * @param groupId the group ID
 * @return the number of matching artists
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByU_G(long userId, long groupId) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_G;
    Object[] finderArgs = new Object[] { userId, groupId };
    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(3);
        query.append(_SQL_COUNT_ARTIST_WHERE);
        query.append(_FINDER_COLUMN_U_G_USERID_2);
        query.append(_FINDER_COLUMN_U_G_GROUPID_2);
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(userId);
            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) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchArtistException(org.liferay.jukebox.NoSuchArtistException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 42 with QueryPos

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

the class ArtistPersistenceImpl method countByGroupId.

/**
 * Returns the number of artists where groupId = ?.
 *
 * @param groupId the group ID
 * @return the number of matching artists
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByGroupId(long groupId) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
    Object[] finderArgs = new Object[] { groupId };
    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(2);
        query.append(_SQL_COUNT_ARTIST_WHERE);
        query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            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) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchArtistException(org.liferay.jukebox.NoSuchArtistException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 43 with QueryPos

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

the class ArtistPersistenceImpl method getByCompanyId_PrevAndNext.

protected Artist getByCompanyId_PrevAndNext(Session session, Artist artist, 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_ARTIST_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(ArtistModelImpl.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(artist);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<Artist> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : Artist(org.liferay.jukebox.model.Artist) SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 44 with QueryPos

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

the class ArtistPersistenceImpl method getByGroupId_PrevAndNext.

protected Artist getByGroupId_PrevAndNext(Session session, Artist artist, long groupId, 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_ARTIST_WHERE);
    query.append(_FINDER_COLUMN_GROUPID_GROUPID_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(ArtistModelImpl.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(groupId);
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(artist);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<Artist> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : Artist(org.liferay.jukebox.model.Artist) SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 45 with QueryPos

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

the class ArtistPersistenceImpl method getByUserId_PrevAndNext.

protected Artist getByUserId_PrevAndNext(Session session, Artist artist, long userId, 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_ARTIST_WHERE);
    query.append(_FINDER_COLUMN_USERID_USERID_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(ArtistModelImpl.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(userId);
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(artist);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<Artist> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : Artist(org.liferay.jukebox.model.Artist) SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Aggregations

QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)471 StringBundler (com.liferay.portal.kernel.util.StringBundler)469 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)407 Session (com.liferay.portal.kernel.dao.orm.Session)344 Query (com.liferay.portal.kernel.dao.orm.Query)338 SystemException (com.liferay.portal.kernel.exception.SystemException)324 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)197 List (java.util.List)164 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)162 ArrayList (java.util.ArrayList)162 NoSuchArticleException (com.liferay.knowledgebase.NoSuchArticleException)144 KBArticle (com.liferay.knowledgebase.model.KBArticle)142 Song (org.liferay.jukebox.model.Song)39 NoSuchSongException (org.liferay.jukebox.NoSuchSongException)36 Album (org.liferay.jukebox.model.Album)36 NoSuchAlbumException (org.liferay.jukebox.NoSuchAlbumException)32 Artist (org.liferay.jukebox.model.Artist)29 NoSuchArtistException (org.liferay.jukebox.NoSuchArtistException)26 NoSuchCommentException (com.liferay.knowledgebase.NoSuchCommentException)20 NoSuchNodeException (com.liferay.portlet.wiki.NoSuchNodeException)20