/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.ese.ils.beta.service.persistence;
import com.ese.ils.beta.NoSuchFavoriteException;
import com.ese.ils.beta.model.Favorite;
import com.ese.ils.beta.model.impl.FavoriteImpl;
import com.ese.ils.beta.model.impl.FavoriteModelImpl;
import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* The persistence implementation for the favorite service.
*
* <p>
* Caching information and settings can be found in <code>portal.properties</code>
* </p>
*
* @author edik
* @see FavoritePersistence
* @see FavoriteUtil
* @generated
*/
public class FavoritePersistenceImpl extends BasePersistenceImpl<Favorite>
implements FavoritePersistence {
/*
* NOTE FOR DEVELOPERS:
*
* Never modify or reference this class directly. Always use {@link FavoriteUtil} to access the favorite persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
*/
public static final String FINDER_CLASS_NAME_ENTITY = FavoriteImpl.class.getName();
public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
".List1";
public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
".List2";
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_BYUSER = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByByUser",
new String[] {
Long.class.getName(),
"java.lang.Integer", "java.lang.Integer",
"com.liferay.portal.kernel.util.OrderByComparator"
});
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYUSER =
new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByByUser",
new String[] { Long.class.getName() },
FavoriteModelImpl.USERID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_BYUSER = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByByUser",
new String[] { Long.class.getName() });
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_BYSLIDE = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByBySlide",
new String[] {
Long.class.getName(),
"java.lang.Integer", "java.lang.Integer",
"com.liferay.portal.kernel.util.OrderByComparator"
});
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYSLIDE =
new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByBySlide",
new String[] { Long.class.getName() },
FavoriteModelImpl.SLIDEID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_BYSLIDE = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByBySlide",
new String[] { Long.class.getName() });
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERMODULE =
new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserModule",
new String[] {
Long.class.getName(), Long.class.getName(),
"java.lang.Integer", "java.lang.Integer",
"com.liferay.portal.kernel.util.OrderByComparator"
});
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERMODULE =
new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserModule",
new String[] { Long.class.getName(), Long.class.getName() },
FavoriteModelImpl.USERID_COLUMN_BITMASK |
FavoriteModelImpl.MODULEID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_USERMODULE = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserModule",
new String[] { Long.class.getName(), Long.class.getName() });
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERANDSLIDE =
new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserAndSlide",
new String[] {
Long.class.getName(), Long.class.getName(),
"java.lang.Integer", "java.lang.Integer",
"com.liferay.portal.kernel.util.OrderByComparator"
});
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDSLIDE =
new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserAndSlide",
new String[] { Long.class.getName(), Long.class.getName() },
FavoriteModelImpl.USERID_COLUMN_BITMASK |
FavoriteModelImpl.SLIDEID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_USERANDSLIDE = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserAndSlide",
new String[] { Long.class.getName(), Long.class.getName() });
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, FavoriteImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
/**
* Caches the favorite in the entity cache if it is enabled.
*
* @param favorite the favorite
*/
public void cacheResult(Favorite favorite) {
EntityCacheUtil.putResult(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteImpl.class, favorite.getPrimaryKey(), favorite);
favorite.resetOriginalValues();
}
/**
* Caches the favorites in the entity cache if it is enabled.
*
* @param favorites the favorites
*/
public void cacheResult(List<Favorite> favorites) {
for (Favorite favorite : favorites) {
if (EntityCacheUtil.getResult(
FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteImpl.class, favorite.getPrimaryKey()) == null) {
cacheResult(favorite);
}
else {
favorite.resetOriginalValues();
}
}
}
/**
* Clears the cache for all favorites.
*
* <p>
* The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
* </p>
*/
@Override
public void clearCache() {
if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
CacheRegistryUtil.clear(FavoriteImpl.class.getName());
}
EntityCacheUtil.clearCache(FavoriteImpl.class.getName());
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
/**
* Clears the cache for the favorite.
*
* <p>
* The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
* </p>
*/
@Override
public void clearCache(Favorite favorite) {
EntityCacheUtil.removeResult(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteImpl.class, favorite.getPrimaryKey());
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
@Override
public void clearCache(List<Favorite> favorites) {
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
for (Favorite favorite : favorites) {
EntityCacheUtil.removeResult(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteImpl.class, favorite.getPrimaryKey());
}
}
/**
* Creates a new favorite with the primary key. Does not add the favorite to the database.
*
* @param favoriteId the primary key for the new favorite
* @return the new favorite
*/
public Favorite create(long favoriteId) {
Favorite favorite = new FavoriteImpl();
favorite.setNew(true);
favorite.setPrimaryKey(favoriteId);
return favorite;
}
/**
* Removes the favorite with the primary key from the database. Also notifies the appropriate model listeners.
*
* @param favoriteId the primary key of the favorite
* @return the favorite that was removed
* @throws com.ese.ils.beta.NoSuchFavoriteException if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite remove(long favoriteId)
throws NoSuchFavoriteException, SystemException {
return remove(Long.valueOf(favoriteId));
}
/**
* Removes the favorite with the primary key from the database. Also notifies the appropriate model listeners.
*
* @param primaryKey the primary key of the favorite
* @return the favorite that was removed
* @throws com.ese.ils.beta.NoSuchFavoriteException if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public Favorite remove(Serializable primaryKey)
throws NoSuchFavoriteException, SystemException {
Session session = null;
try {
session = openSession();
Favorite favorite = (Favorite)session.get(FavoriteImpl.class,
primaryKey);
if (favorite == null) {
if (_log.isWarnEnabled()) {
_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
}
throw new NoSuchFavoriteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
primaryKey);
}
return remove(favorite);
}
catch (NoSuchFavoriteException nsee) {
throw nsee;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
@Override
protected Favorite removeImpl(Favorite favorite) throws SystemException {
favorite = toUnwrappedModel(favorite);
Session session = null;
try {
session = openSession();
BatchSessionUtil.delete(session, favorite);
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
clearCache(favorite);
return favorite;
}
@Override
public Favorite updateImpl(com.ese.ils.beta.model.Favorite favorite,
boolean merge) throws SystemException {
favorite = toUnwrappedModel(favorite);
boolean isNew = favorite.isNew();
FavoriteModelImpl favoriteModelImpl = (FavoriteModelImpl)favorite;
Session session = null;
try {
session = openSession();
BatchSessionUtil.update(session, favorite, merge);
favorite.setNew(false);
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
if (isNew || !FavoriteModelImpl.COLUMN_BITMASK_ENABLED) {
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
else {
if ((favoriteModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYUSER.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(favoriteModelImpl.getOriginalUserId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BYUSER, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYUSER,
args);
args = new Object[] { Long.valueOf(favoriteModelImpl.getUserId()) };
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BYUSER, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYUSER,
args);
}
if ((favoriteModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYSLIDE.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(favoriteModelImpl.getOriginalSlideId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BYSLIDE, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYSLIDE,
args);
args = new Object[] { Long.valueOf(favoriteModelImpl.getSlideId()) };
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BYSLIDE, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYSLIDE,
args);
}
if ((favoriteModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERMODULE.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(favoriteModelImpl.getOriginalUserId()),
Long.valueOf(favoriteModelImpl.getOriginalModuleId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERMODULE,
args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERMODULE,
args);
args = new Object[] {
Long.valueOf(favoriteModelImpl.getUserId()),
Long.valueOf(favoriteModelImpl.getModuleId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERMODULE,
args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERMODULE,
args);
}
if ((favoriteModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDSLIDE.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(favoriteModelImpl.getOriginalUserId()),
Long.valueOf(favoriteModelImpl.getOriginalSlideId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERANDSLIDE,
args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDSLIDE,
args);
args = new Object[] {
Long.valueOf(favoriteModelImpl.getUserId()),
Long.valueOf(favoriteModelImpl.getSlideId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERANDSLIDE,
args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDSLIDE,
args);
}
}
EntityCacheUtil.putResult(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteImpl.class, favorite.getPrimaryKey(), favorite);
return favorite;
}
protected Favorite toUnwrappedModel(Favorite favorite) {
if (favorite instanceof FavoriteImpl) {
return favorite;
}
FavoriteImpl favoriteImpl = new FavoriteImpl();
favoriteImpl.setNew(favorite.isNew());
favoriteImpl.setPrimaryKey(favorite.getPrimaryKey());
favoriteImpl.setFavoriteId(favorite.getFavoriteId());
favoriteImpl.setUserId(favorite.getUserId());
favoriteImpl.setModuleId(favorite.getModuleId());
favoriteImpl.setSlideId(favorite.getSlideId());
return favoriteImpl;
}
/**
* Returns the favorite with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
*
* @param primaryKey the primary key of the favorite
* @return the favorite
* @throws com.liferay.portal.NoSuchModelException if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public Favorite findByPrimaryKey(Serializable primaryKey)
throws NoSuchModelException, SystemException {
return findByPrimaryKey(((Long)primaryKey).longValue());
}
/**
* Returns the favorite with the primary key or throws a {@link com.ese.ils.beta.NoSuchFavoriteException} if it could not be found.
*
* @param favoriteId the primary key of the favorite
* @return the favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByPrimaryKey(long favoriteId)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByPrimaryKey(favoriteId);
if (favorite == null) {
if (_log.isWarnEnabled()) {
_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + favoriteId);
}
throw new NoSuchFavoriteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
favoriteId);
}
return favorite;
}
/**
* Returns the favorite with the primary key or returns <code>null</code> if it could not be found.
*
* @param primaryKey the primary key of the favorite
* @return the favorite, or <code>null</code> if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public Favorite fetchByPrimaryKey(Serializable primaryKey)
throws SystemException {
return fetchByPrimaryKey(((Long)primaryKey).longValue());
}
/**
* Returns the favorite with the primary key or returns <code>null</code> if it could not be found.
*
* @param favoriteId the primary key of the favorite
* @return the favorite, or <code>null</code> if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByPrimaryKey(long favoriteId)
throws SystemException {
Favorite favorite = (Favorite)EntityCacheUtil.getResult(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteImpl.class, favoriteId);
if (favorite == _nullFavorite) {
return null;
}
if (favorite == null) {
Session session = null;
boolean hasException = false;
try {
session = openSession();
favorite = (Favorite)session.get(FavoriteImpl.class,
Long.valueOf(favoriteId));
}
catch (Exception e) {
hasException = true;
throw processException(e);
}
finally {
if (favorite != null) {
cacheResult(favorite);
}
else if (!hasException) {
EntityCacheUtil.putResult(FavoriteModelImpl.ENTITY_CACHE_ENABLED,
FavoriteImpl.class, favoriteId, _nullFavorite);
}
closeSession(session);
}
}
return favorite;
}
/**
* Returns all the favorites where userId = ?.
*
* @param userId the user ID
* @return the matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByByUser(long userId) throws SystemException {
return findByByUser(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the favorites where userId = ?.
*
* <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.
* </p>
*
* @param userId the user ID
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @return the range of matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByByUser(long userId, int start, int end)
throws SystemException {
return findByByUser(userId, start, end, null);
}
/**
* Returns an ordered range of all the favorites where userId = ?.
*
* <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.
* </p>
*
* @param userId the user ID
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByByUser(long userId, int start, int end,
OrderByComparator orderByComparator) throws SystemException {
FinderPath finderPath = null;
Object[] finderArgs = null;
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYUSER;
finderArgs = new Object[] { userId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BYUSER;
finderArgs = new Object[] { userId, start, end, orderByComparator };
}
List<Favorite> list = (List<Favorite>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Favorite favorite : list) {
if ((userId != favorite.getUserId())) {
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_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_BYUSER_USERID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else {
query.append(FavoriteModelImpl.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(userId);
list = (List<Favorite>)QueryUtil.list(q, getDialect(), start,
end);
}
catch (Exception e) {
throw processException(e);
}
finally {
if (list == null) {
FinderCacheUtil.removeResult(finderPath, finderArgs);
}
else {
cacheResult(list);
FinderCacheUtil.putResult(finderPath, finderArgs, list);
}
closeSession(session);
}
}
return list;
}
/**
* Returns the first favorite in the ordered set where userId = ?.
*
* @param userId the user ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByByUser_First(long userId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByByUser_First(userId, orderByComparator);
if (favorite != null) {
return favorite;
}
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 NoSuchFavoriteException(msg.toString());
}
/**
* Returns the first favorite in the ordered set where userId = ?.
*
* @param userId the user ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching favorite, or <code>null</code> if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByByUser_First(long userId,
OrderByComparator orderByComparator) throws SystemException {
List<Favorite> list = findByByUser(userId, 0, 1, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last favorite in the ordered set where userId = ?.
*
* @param userId the user ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByByUser_Last(long userId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByByUser_Last(userId, orderByComparator);
if (favorite != null) {
return favorite;
}
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 NoSuchFavoriteException(msg.toString());
}
/**
* Returns the last favorite in the ordered set where userId = ?.
*
* @param userId the user ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching favorite, or <code>null</code> if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByByUser_Last(long userId,
OrderByComparator orderByComparator) throws SystemException {
int count = countByByUser(userId);
List<Favorite> list = findByByUser(userId, count - 1, count,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the favorites before and after the current favorite in the ordered set where userId = ?.
*
* @param favoriteId the primary key of the current favorite
* @param userId the user ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite[] findByByUser_PrevAndNext(long favoriteId, long userId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = findByPrimaryKey(favoriteId);
Session session = null;
try {
session = openSession();
Favorite[] array = new FavoriteImpl[3];
array[0] = getByByUser_PrevAndNext(session, favorite, userId,
orderByComparator, true);
array[1] = favorite;
array[2] = getByByUser_PrevAndNext(session, favorite, userId,
orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Favorite getByByUser_PrevAndNext(Session session,
Favorite favorite, 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_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_BYUSER_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(FavoriteModelImpl.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(favorite);
for (Object value : values) {
qPos.add(value);
}
}
List<Favorite> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the favorites where slideId = ?.
*
* @param slideId the slide ID
* @return the matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByBySlide(long slideId) throws SystemException {
return findByBySlide(slideId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the favorites where slideId = ?.
*
* <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.
* </p>
*
* @param slideId the slide ID
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @return the range of matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByBySlide(long slideId, int start, int end)
throws SystemException {
return findByBySlide(slideId, start, end, null);
}
/**
* Returns an ordered range of all the favorites where slideId = ?.
*
* <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.
* </p>
*
* @param slideId the slide ID
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByBySlide(long slideId, int start, int end,
OrderByComparator orderByComparator) throws SystemException {
FinderPath finderPath = null;
Object[] finderArgs = null;
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYSLIDE;
finderArgs = new Object[] { slideId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BYSLIDE;
finderArgs = new Object[] { slideId, start, end, orderByComparator };
}
List<Favorite> list = (List<Favorite>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Favorite favorite : list) {
if ((slideId != favorite.getSlideId())) {
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_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_BYSLIDE_SLIDEID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else {
query.append(FavoriteModelImpl.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(slideId);
list = (List<Favorite>)QueryUtil.list(q, getDialect(), start,
end);
}
catch (Exception e) {
throw processException(e);
}
finally {
if (list == null) {
FinderCacheUtil.removeResult(finderPath, finderArgs);
}
else {
cacheResult(list);
FinderCacheUtil.putResult(finderPath, finderArgs, list);
}
closeSession(session);
}
}
return list;
}
/**
* Returns the first favorite in the ordered set where slideId = ?.
*
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByBySlide_First(long slideId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByBySlide_First(slideId, orderByComparator);
if (favorite != null) {
return favorite;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("slideId=");
msg.append(slideId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchFavoriteException(msg.toString());
}
/**
* Returns the first favorite in the ordered set where slideId = ?.
*
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching favorite, or <code>null</code> if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByBySlide_First(long slideId,
OrderByComparator orderByComparator) throws SystemException {
List<Favorite> list = findByBySlide(slideId, 0, 1, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last favorite in the ordered set where slideId = ?.
*
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByBySlide_Last(long slideId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByBySlide_Last(slideId, orderByComparator);
if (favorite != null) {
return favorite;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("slideId=");
msg.append(slideId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchFavoriteException(msg.toString());
}
/**
* Returns the last favorite in the ordered set where slideId = ?.
*
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching favorite, or <code>null</code> if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByBySlide_Last(long slideId,
OrderByComparator orderByComparator) throws SystemException {
int count = countByBySlide(slideId);
List<Favorite> list = findByBySlide(slideId, count - 1, count,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the favorites before and after the current favorite in the ordered set where slideId = ?.
*
* @param favoriteId the primary key of the current favorite
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite[] findByBySlide_PrevAndNext(long favoriteId, long slideId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = findByPrimaryKey(favoriteId);
Session session = null;
try {
session = openSession();
Favorite[] array = new FavoriteImpl[3];
array[0] = getByBySlide_PrevAndNext(session, favorite, slideId,
orderByComparator, true);
array[1] = favorite;
array[2] = getByBySlide_PrevAndNext(session, favorite, slideId,
orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Favorite getByBySlide_PrevAndNext(Session session,
Favorite favorite, long slideId, 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_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_BYSLIDE_SLIDEID_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(FavoriteModelImpl.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(slideId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(favorite);
for (Object value : values) {
qPos.add(value);
}
}
List<Favorite> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the favorites where userId = ? and moduleId = ?.
*
* @param userId the user ID
* @param moduleId the module ID
* @return the matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByUserModule(long userId, long moduleId)
throws SystemException {
return findByUserModule(userId, moduleId, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the favorites where userId = ? and moduleId = ?.
*
* <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.
* </p>
*
* @param userId the user ID
* @param moduleId the module ID
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @return the range of matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByUserModule(long userId, long moduleId,
int start, int end) throws SystemException {
return findByUserModule(userId, moduleId, start, end, null);
}
/**
* Returns an ordered range of all the favorites where userId = ? and moduleId = ?.
*
* <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.
* </p>
*
* @param userId the user ID
* @param moduleId the module ID
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByUserModule(long userId, long moduleId,
int start, int end, OrderByComparator orderByComparator)
throws SystemException {
FinderPath finderPath = null;
Object[] finderArgs = null;
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERMODULE;
finderArgs = new Object[] { userId, moduleId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERMODULE;
finderArgs = new Object[] {
userId, moduleId,
start, end, orderByComparator
};
}
List<Favorite> list = (List<Favorite>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Favorite favorite : list) {
if ((userId != favorite.getUserId()) ||
(moduleId != favorite.getModuleId())) {
list = null;
break;
}
}
}
if (list == null) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(4 +
(orderByComparator.getOrderByFields().length * 3));
}
else {
query = new StringBundler(4);
}
query.append(_SQL_SELECT_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_USERMODULE_USERID_2);
query.append(_FINDER_COLUMN_USERMODULE_MODULEID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else {
query.append(FavoriteModelImpl.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(userId);
qPos.add(moduleId);
list = (List<Favorite>)QueryUtil.list(q, getDialect(), start,
end);
}
catch (Exception e) {
throw processException(e);
}
finally {
if (list == null) {
FinderCacheUtil.removeResult(finderPath, finderArgs);
}
else {
cacheResult(list);
FinderCacheUtil.putResult(finderPath, finderArgs, list);
}
closeSession(session);
}
}
return list;
}
/**
* Returns the first favorite in the ordered set where userId = ? and moduleId = ?.
*
* @param userId the user ID
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByUserModule_First(long userId, long moduleId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByUserModule_First(userId, moduleId,
orderByComparator);
if (favorite != null) {
return favorite;
}
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("userId=");
msg.append(userId);
msg.append(", moduleId=");
msg.append(moduleId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchFavoriteException(msg.toString());
}
/**
* Returns the first favorite in the ordered set where userId = ? and moduleId = ?.
*
* @param userId the user ID
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching favorite, or <code>null</code> if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByUserModule_First(long userId, long moduleId,
OrderByComparator orderByComparator) throws SystemException {
List<Favorite> list = findByUserModule(userId, moduleId, 0, 1,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last favorite in the ordered set where userId = ? and moduleId = ?.
*
* @param userId the user ID
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByUserModule_Last(long userId, long moduleId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByUserModule_Last(userId, moduleId,
orderByComparator);
if (favorite != null) {
return favorite;
}
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("userId=");
msg.append(userId);
msg.append(", moduleId=");
msg.append(moduleId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchFavoriteException(msg.toString());
}
/**
* Returns the last favorite in the ordered set where userId = ? and moduleId = ?.
*
* @param userId the user ID
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching favorite, or <code>null</code> if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByUserModule_Last(long userId, long moduleId,
OrderByComparator orderByComparator) throws SystemException {
int count = countByUserModule(userId, moduleId);
List<Favorite> list = findByUserModule(userId, moduleId, count - 1,
count, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the favorites before and after the current favorite in the ordered set where userId = ? and moduleId = ?.
*
* @param favoriteId the primary key of the current favorite
* @param userId the user ID
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite[] findByUserModule_PrevAndNext(long favoriteId,
long userId, long moduleId, OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = findByPrimaryKey(favoriteId);
Session session = null;
try {
session = openSession();
Favorite[] array = new FavoriteImpl[3];
array[0] = getByUserModule_PrevAndNext(session, favorite, userId,
moduleId, orderByComparator, true);
array[1] = favorite;
array[2] = getByUserModule_PrevAndNext(session, favorite, userId,
moduleId, orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Favorite getByUserModule_PrevAndNext(Session session,
Favorite favorite, long userId, long moduleId,
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_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_USERMODULE_USERID_2);
query.append(_FINDER_COLUMN_USERMODULE_MODULEID_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(FavoriteModelImpl.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);
qPos.add(moduleId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(favorite);
for (Object value : values) {
qPos.add(value);
}
}
List<Favorite> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the favorites where userId = ? and slideId = ?.
*
* @param userId the user ID
* @param slideId the slide ID
* @return the matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByUserAndSlide(long userId, long slideId)
throws SystemException {
return findByUserAndSlide(userId, slideId, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the favorites where userId = ? and slideId = ?.
*
* <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.
* </p>
*
* @param userId the user ID
* @param slideId the slide ID
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @return the range of matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByUserAndSlide(long userId, long slideId,
int start, int end) throws SystemException {
return findByUserAndSlide(userId, slideId, start, end, null);
}
/**
* Returns an ordered range of all the favorites where userId = ? and slideId = ?.
*
* <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.
* </p>
*
* @param userId the user ID
* @param slideId the slide ID
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findByUserAndSlide(long userId, long slideId,
int start, int end, OrderByComparator orderByComparator)
throws SystemException {
FinderPath finderPath = null;
Object[] finderArgs = null;
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDSLIDE;
finderArgs = new Object[] { userId, slideId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERANDSLIDE;
finderArgs = new Object[] {
userId, slideId,
start, end, orderByComparator
};
}
List<Favorite> list = (List<Favorite>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Favorite favorite : list) {
if ((userId != favorite.getUserId()) ||
(slideId != favorite.getSlideId())) {
list = null;
break;
}
}
}
if (list == null) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(4 +
(orderByComparator.getOrderByFields().length * 3));
}
else {
query = new StringBundler(4);
}
query.append(_SQL_SELECT_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_USERANDSLIDE_USERID_2);
query.append(_FINDER_COLUMN_USERANDSLIDE_SLIDEID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else {
query.append(FavoriteModelImpl.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(userId);
qPos.add(slideId);
list = (List<Favorite>)QueryUtil.list(q, getDialect(), start,
end);
}
catch (Exception e) {
throw processException(e);
}
finally {
if (list == null) {
FinderCacheUtil.removeResult(finderPath, finderArgs);
}
else {
cacheResult(list);
FinderCacheUtil.putResult(finderPath, finderArgs, list);
}
closeSession(session);
}
}
return list;
}
/**
* Returns the first favorite in the ordered set where userId = ? and slideId = ?.
*
* @param userId the user ID
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByUserAndSlide_First(long userId, long slideId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByUserAndSlide_First(userId, slideId,
orderByComparator);
if (favorite != null) {
return favorite;
}
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("userId=");
msg.append(userId);
msg.append(", slideId=");
msg.append(slideId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchFavoriteException(msg.toString());
}
/**
* Returns the first favorite in the ordered set where userId = ? and slideId = ?.
*
* @param userId the user ID
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching favorite, or <code>null</code> if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByUserAndSlide_First(long userId, long slideId,
OrderByComparator orderByComparator) throws SystemException {
List<Favorite> list = findByUserAndSlide(userId, slideId, 0, 1,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last favorite in the ordered set where userId = ? and slideId = ?.
*
* @param userId the user ID
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite findByUserAndSlide_Last(long userId, long slideId,
OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = fetchByUserAndSlide_Last(userId, slideId,
orderByComparator);
if (favorite != null) {
return favorite;
}
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("userId=");
msg.append(userId);
msg.append(", slideId=");
msg.append(slideId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchFavoriteException(msg.toString());
}
/**
* Returns the last favorite in the ordered set where userId = ? and slideId = ?.
*
* @param userId the user ID
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching favorite, or <code>null</code> if a matching favorite could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite fetchByUserAndSlide_Last(long userId, long slideId,
OrderByComparator orderByComparator) throws SystemException {
int count = countByUserAndSlide(userId, slideId);
List<Favorite> list = findByUserAndSlide(userId, slideId, count - 1,
count, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the favorites before and after the current favorite in the ordered set where userId = ? and slideId = ?.
*
* @param favoriteId the primary key of the current favorite
* @param userId the user ID
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next favorite
* @throws com.ese.ils.beta.NoSuchFavoriteException if a favorite with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Favorite[] findByUserAndSlide_PrevAndNext(long favoriteId,
long userId, long slideId, OrderByComparator orderByComparator)
throws NoSuchFavoriteException, SystemException {
Favorite favorite = findByPrimaryKey(favoriteId);
Session session = null;
try {
session = openSession();
Favorite[] array = new FavoriteImpl[3];
array[0] = getByUserAndSlide_PrevAndNext(session, favorite, userId,
slideId, orderByComparator, true);
array[1] = favorite;
array[2] = getByUserAndSlide_PrevAndNext(session, favorite, userId,
slideId, orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Favorite getByUserAndSlide_PrevAndNext(Session session,
Favorite favorite, long userId, long slideId,
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_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_USERANDSLIDE_USERID_2);
query.append(_FINDER_COLUMN_USERANDSLIDE_SLIDEID_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(FavoriteModelImpl.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);
qPos.add(slideId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(favorite);
for (Object value : values) {
qPos.add(value);
}
}
List<Favorite> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the favorites.
*
* @return the favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findAll() throws SystemException {
return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the favorites.
*
* <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.
* </p>
*
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @return the range of favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findAll(int start, int end) throws SystemException {
return findAll(start, end, null);
}
/**
* Returns an ordered range of all the favorites.
*
* <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.
* </p>
*
* @param start the lower bound of the range of favorites
* @param end the upper bound of the range of favorites (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of favorites
* @throws SystemException if a system exception occurred
*/
public List<Favorite> findAll(int start, int end,
OrderByComparator orderByComparator) throws SystemException {
FinderPath finderPath = null;
Object[] finderArgs = new Object[] { start, end, orderByComparator };
if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
(orderByComparator == null)) {
finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
finderArgs = FINDER_ARGS_EMPTY;
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
finderArgs = new Object[] { start, end, orderByComparator };
}
List<Favorite> list = (List<Favorite>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if (list == null) {
StringBundler query = null;
String sql = null;
if (orderByComparator != null) {
query = new StringBundler(2 +
(orderByComparator.getOrderByFields().length * 3));
query.append(_SQL_SELECT_FAVORITE);
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
sql = query.toString();
}
else {
sql = _SQL_SELECT_FAVORITE.concat(FavoriteModelImpl.ORDER_BY_JPQL);
}
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
if (orderByComparator == null) {
list = (List<Favorite>)QueryUtil.list(q, getDialect(),
start, end, false);
Collections.sort(list);
}
else {
list = (List<Favorite>)QueryUtil.list(q, getDialect(),
start, end);
}
}
catch (Exception e) {
throw processException(e);
}
finally {
if (list == null) {
FinderCacheUtil.removeResult(finderPath, finderArgs);
}
else {
cacheResult(list);
FinderCacheUtil.putResult(finderPath, finderArgs, list);
}
closeSession(session);
}
}
return list;
}
/**
* Removes all the favorites where userId = ? from the database.
*
* @param userId the user ID
* @throws SystemException if a system exception occurred
*/
public void removeByByUser(long userId) throws SystemException {
for (Favorite favorite : findByByUser(userId)) {
remove(favorite);
}
}
/**
* Removes all the favorites where slideId = ? from the database.
*
* @param slideId the slide ID
* @throws SystemException if a system exception occurred
*/
public void removeByBySlide(long slideId) throws SystemException {
for (Favorite favorite : findByBySlide(slideId)) {
remove(favorite);
}
}
/**
* Removes all the favorites where userId = ? and moduleId = ? from the database.
*
* @param userId the user ID
* @param moduleId the module ID
* @throws SystemException if a system exception occurred
*/
public void removeByUserModule(long userId, long moduleId)
throws SystemException {
for (Favorite favorite : findByUserModule(userId, moduleId)) {
remove(favorite);
}
}
/**
* Removes all the favorites where userId = ? and slideId = ? from the database.
*
* @param userId the user ID
* @param slideId the slide ID
* @throws SystemException if a system exception occurred
*/
public void removeByUserAndSlide(long userId, long slideId)
throws SystemException {
for (Favorite favorite : findByUserAndSlide(userId, slideId)) {
remove(favorite);
}
}
/**
* Removes all the favorites from the database.
*
* @throws SystemException if a system exception occurred
*/
public void removeAll() throws SystemException {
for (Favorite favorite : findAll()) {
remove(favorite);
}
}
/**
* Returns the number of favorites where userId = ?.
*
* @param userId the user ID
* @return the number of matching favorites
* @throws SystemException if a system exception occurred
*/
public int countByByUser(long userId) throws SystemException {
Object[] finderArgs = new Object[] { userId };
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BYUSER,
finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(2);
query.append(_SQL_COUNT_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_BYUSER_USERID_2);
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(userId);
count = (Long)q.uniqueResult();
}
catch (Exception e) {
throw processException(e);
}
finally {
if (count == null) {
count = Long.valueOf(0);
}
FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BYUSER,
finderArgs, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Returns the number of favorites where slideId = ?.
*
* @param slideId the slide ID
* @return the number of matching favorites
* @throws SystemException if a system exception occurred
*/
public int countByBySlide(long slideId) throws SystemException {
Object[] finderArgs = new Object[] { slideId };
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BYSLIDE,
finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(2);
query.append(_SQL_COUNT_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_BYSLIDE_SLIDEID_2);
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(slideId);
count = (Long)q.uniqueResult();
}
catch (Exception e) {
throw processException(e);
}
finally {
if (count == null) {
count = Long.valueOf(0);
}
FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BYSLIDE,
finderArgs, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Returns the number of favorites where userId = ? and moduleId = ?.
*
* @param userId the user ID
* @param moduleId the module ID
* @return the number of matching favorites
* @throws SystemException if a system exception occurred
*/
public int countByUserModule(long userId, long moduleId)
throws SystemException {
Object[] finderArgs = new Object[] { userId, moduleId };
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERMODULE,
finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(3);
query.append(_SQL_COUNT_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_USERMODULE_USERID_2);
query.append(_FINDER_COLUMN_USERMODULE_MODULEID_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(moduleId);
count = (Long)q.uniqueResult();
}
catch (Exception e) {
throw processException(e);
}
finally {
if (count == null) {
count = Long.valueOf(0);
}
FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERMODULE,
finderArgs, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Returns the number of favorites where userId = ? and slideId = ?.
*
* @param userId the user ID
* @param slideId the slide ID
* @return the number of matching favorites
* @throws SystemException if a system exception occurred
*/
public int countByUserAndSlide(long userId, long slideId)
throws SystemException {
Object[] finderArgs = new Object[] { userId, slideId };
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERANDSLIDE,
finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(3);
query.append(_SQL_COUNT_FAVORITE_WHERE);
query.append(_FINDER_COLUMN_USERANDSLIDE_USERID_2);
query.append(_FINDER_COLUMN_USERANDSLIDE_SLIDEID_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(slideId);
count = (Long)q.uniqueResult();
}
catch (Exception e) {
throw processException(e);
}
finally {
if (count == null) {
count = Long.valueOf(0);
}
FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERANDSLIDE,
finderArgs, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Returns the number of favorites.
*
* @return the number of favorites
* @throws SystemException if a system exception occurred
*/
public int countAll() throws SystemException {
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
FINDER_ARGS_EMPTY, this);
if (count == null) {
Session session = null;
try {
session = openSession();
Query q = session.createQuery(_SQL_COUNT_FAVORITE);
count = (Long)q.uniqueResult();
}
catch (Exception e) {
throw processException(e);
}
finally {
if (count == null) {
count = Long.valueOf(0);
}
FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
FINDER_ARGS_EMPTY, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Initializes the favorite persistence.
*/
public void afterPropertiesSet() {
String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
com.liferay.util.service.ServiceProps.get(
"value.object.listener.com.ese.ils.beta.model.Favorite")));
if (listenerClassNames.length > 0) {
try {
List<ModelListener<Favorite>> listenersList = new ArrayList<ModelListener<Favorite>>();
for (String listenerClassName : listenerClassNames) {
listenersList.add((ModelListener<Favorite>)InstanceFactory.newInstance(
listenerClassName));
}
listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
}
catch (Exception e) {
_log.error(e);
}
}
}
public void destroy() {
EntityCacheUtil.removeCache(FavoriteImpl.class.getName());
FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
@BeanReference(type = FavoritePersistence.class)
protected FavoritePersistence favoritePersistence;
@BeanReference(type = ModulePersistence.class)
protected ModulePersistence modulePersistence;
@BeanReference(type = PanicButtonPersistence.class)
protected PanicButtonPersistence panicButtonPersistence;
@BeanReference(type = QuestionPersistence.class)
protected QuestionPersistence questionPersistence;
@BeanReference(type = SlidePersistence.class)
protected SlidePersistence slidePersistence;
@BeanReference(type = UserInfoPersistence.class)
protected UserInfoPersistence userInfoPersistence;
@BeanReference(type = ResourcePersistence.class)
protected ResourcePersistence resourcePersistence;
@BeanReference(type = UserPersistence.class)
protected UserPersistence userPersistence;
private static final String _SQL_SELECT_FAVORITE = "SELECT favorite FROM Favorite favorite";
private static final String _SQL_SELECT_FAVORITE_WHERE = "SELECT favorite FROM Favorite favorite WHERE ";
private static final String _SQL_COUNT_FAVORITE = "SELECT COUNT(favorite) FROM Favorite favorite";
private static final String _SQL_COUNT_FAVORITE_WHERE = "SELECT COUNT(favorite) FROM Favorite favorite WHERE ";
private static final String _FINDER_COLUMN_BYUSER_USERID_2 = "favorite.userId = ?";
private static final String _FINDER_COLUMN_BYSLIDE_SLIDEID_2 = "favorite.slideId = ?";
private static final String _FINDER_COLUMN_USERMODULE_USERID_2 = "favorite.userId = ? AND ";
private static final String _FINDER_COLUMN_USERMODULE_MODULEID_2 = "favorite.moduleId = ?";
private static final String _FINDER_COLUMN_USERANDSLIDE_USERID_2 = "favorite.userId = ? AND ";
private static final String _FINDER_COLUMN_USERANDSLIDE_SLIDEID_2 = "favorite.slideId = ?";
private static final String _ORDER_BY_ENTITY_ALIAS = "favorite.";
private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Favorite exists with the primary key ";
private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Favorite exists with the key {";
private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
private static Log _log = LogFactoryUtil.getLog(FavoritePersistenceImpl.class);
private static Favorite _nullFavorite = new FavoriteImpl() {
@Override
public Object clone() {
return this;
}
@Override
public CacheModel<Favorite> toCacheModel() {
return _nullFavoriteCacheModel;
}
};
private static CacheModel<Favorite> _nullFavoriteCacheModel = new CacheModel<Favorite>() {
public Favorite toEntityModel() {
return _nullFavorite;
}
};
}