Search in sources :

Example 36 with Song

use of org.liferay.jukebox.model.Song in project liferay-ide by liferay.

the class SongPersistenceImpl method findByG_A_S.

/**
 * Returns an ordered range of all the songs where groupId = ? and albumId = ? and status = ?.
 *
 * <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 org.liferay.jukebox.model.impl.SongModelImpl}. 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 albumId the album ID
 * @param status the status
 * @param start the lower bound of the range of songs
 * @param end the upper bound of the range of songs (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching songs
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Song> findByG_A_S(long groupId, long albumId, int status, 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_G_A_S;
        finderArgs = new Object[] { groupId, albumId, status };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_S;
        finderArgs = new Object[] { groupId, albumId, status, start, end, orderByComparator };
    }
    List<Song> list = (List<Song>) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if ((list != null) && !list.isEmpty()) {
        for (Song song : list) {
            if ((groupId != song.getGroupId()) || (albumId != song.getAlbumId()) || (status != song.getStatus())) {
                list = null;
                break;
            }
        }
    }
    if (list == null) {
        StringBundler query = null;
        if (orderByComparator != null) {
            query = new StringBundler(5 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(5);
        }
        query.append(_SQL_SELECT_SONG_WHERE);
        query.append(_FINDER_COLUMN_G_A_S_GROUPID_2);
        query.append(_FINDER_COLUMN_G_A_S_ALBUMID_2);
        query.append(_FINDER_COLUMN_G_A_S_STATUS_2);
        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(SongModelImpl.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);
            qPos.add(albumId);
            qPos.add(status);
            if (!pagination) {
                list = (List<Song>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = new UnmodifiableList<Song>(list);
            } else {
                list = (List<Song>) 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) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchSongException(org.liferay.jukebox.NoSuchSongException) Song(org.liferay.jukebox.model.Song) 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 37 with Song

use of org.liferay.jukebox.model.Song in project liferay-ide by liferay.

the class SongPersistenceImpl method findByUserId_First.

/**
 * Returns the first song in the ordered set where userId = &#63;.
 *
 * @param userId the user ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the first matching song
 * @throws org.liferay.jukebox.NoSuchSongException if a matching song could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Song findByUserId_First(long userId, OrderByComparator orderByComparator) throws NoSuchSongException, SystemException {
    Song song = fetchByUserId_First(userId, orderByComparator);
    if (song != null) {
        return song;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("userId=");
    msg.append(userId);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchSongException(msg.toString());
}
Also used : Song(org.liferay.jukebox.model.Song) NoSuchSongException(org.liferay.jukebox.NoSuchSongException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 38 with Song

use of org.liferay.jukebox.model.Song in project liferay-ide by liferay.

the class SongPersistenceImpl method findByG_A_PrevAndNext.

/**
 * Returns the songs before and after the current song in the ordered set where groupId = &#63; and albumId = &#63;.
 *
 * @param songId the primary key of the current song
 * @param groupId the group ID
 * @param albumId the album ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next song
 * @throws org.liferay.jukebox.NoSuchSongException if a song with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Song[] findByG_A_PrevAndNext(long songId, long groupId, long albumId, OrderByComparator orderByComparator) throws NoSuchSongException, SystemException {
    Song song = findByPrimaryKey(songId);
    Session session = null;
    try {
        session = openSession();
        Song[] array = new SongImpl[3];
        array[0] = getByG_A_PrevAndNext(session, song, groupId, albumId, orderByComparator, true);
        array[1] = song;
        array[2] = getByG_A_PrevAndNext(session, song, groupId, albumId, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Song(org.liferay.jukebox.model.Song) SongImpl(org.liferay.jukebox.model.impl.SongImpl) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchSongException(org.liferay.jukebox.NoSuchSongException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 39 with Song

use of org.liferay.jukebox.model.Song in project liferay-ide by liferay.

the class SongPersistenceImpl method findByUuid_Last.

/**
 * Returns the last song in the ordered set where uuid = &#63;.
 *
 * @param uuid the uuid
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching song
 * @throws org.liferay.jukebox.NoSuchSongException if a matching song could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Song findByUuid_Last(String uuid, OrderByComparator orderByComparator) throws NoSuchSongException, SystemException {
    Song song = fetchByUuid_Last(uuid, orderByComparator);
    if (song != null) {
        return song;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("uuid=");
    msg.append(uuid);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchSongException(msg.toString());
}
Also used : Song(org.liferay.jukebox.model.Song) NoSuchSongException(org.liferay.jukebox.NoSuchSongException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 40 with Song

use of org.liferay.jukebox.model.Song in project liferay-ide by liferay.

the class SongPersistenceImpl method findByUserId_Last.

/**
 * Returns the last song in the ordered set where userId = &#63;.
 *
 * @param userId the user ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching song
 * @throws org.liferay.jukebox.NoSuchSongException if a matching song could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Song findByUserId_Last(long userId, OrderByComparator orderByComparator) throws NoSuchSongException, SystemException {
    Song song = fetchByUserId_Last(userId, orderByComparator);
    if (song != null) {
        return song;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("userId=");
    msg.append(userId);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchSongException(msg.toString());
}
Also used : Song(org.liferay.jukebox.model.Song) NoSuchSongException(org.liferay.jukebox.NoSuchSongException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Aggregations

Song (org.liferay.jukebox.model.Song)110 NoSuchSongException (org.liferay.jukebox.NoSuchSongException)61 StringBundler (com.liferay.portal.kernel.util.StringBundler)59 SystemException (com.liferay.portal.kernel.exception.SystemException)39 Session (com.liferay.portal.kernel.dao.orm.Session)37 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)35 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)34 Query (com.liferay.portal.kernel.dao.orm.Query)25 ArrayList (java.util.ArrayList)22 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)19 List (java.util.List)19 SongImpl (org.liferay.jukebox.model.impl.SongImpl)19 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)12 Indexable (com.liferay.portal.kernel.search.Indexable)9 User (com.liferay.portal.model.User)7 ServiceContext (com.liferay.portal.service.ServiceContext)6 TrashEntry (com.liferay.portlet.trash.model.TrashEntry)6 Date (java.util.Date)6 Album (org.liferay.jukebox.model.Album)6 Folder (com.liferay.portal.kernel.repository.model.Folder)3