/**
* 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.NoSuchQuestionException;
import com.ese.ils.beta.model.Question;
import com.ese.ils.beta.model.impl.QuestionImpl;
import com.ese.ils.beta.model.impl.QuestionModelImpl;
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 question service.
*
* <p>
* Caching information and settings can be found in <code>portal.properties</code>
* </p>
*
* @author edik
* @see QuestionPersistence
* @see QuestionUtil
* @generated
*/
public class QuestionPersistenceImpl extends BasePersistenceImpl<Question>
implements QuestionPersistence {
/*
* NOTE FOR DEVELOPERS:
*
* Never modify or reference this class directly. Always use {@link QuestionUtil} to access the question persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
*/
public static final String FINDER_CLASS_NAME_ENTITY = QuestionImpl.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_USER = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUser",
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_USER = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUser",
new String[] { Long.class.getName() },
QuestionModelImpl.USERID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_USER = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUser",
new String[] { Long.class.getName() });
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_MODULE = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByModule",
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_MODULE =
new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByModule",
new String[] { Long.class.getName() },
QuestionModelImpl.MODULEID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_MODULE = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByModule",
new String[] { Long.class.getName() });
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SLIDE = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySlide",
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_SLIDE = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySlide",
new String[] { Long.class.getName() },
QuestionModelImpl.SLIDEID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_SLIDE = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySlide",
new String[] { Long.class.getName() });
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERANDSLIDE =
new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.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(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserAndSlide",
new String[] { Long.class.getName(), Long.class.getName() },
QuestionModelImpl.USERID_COLUMN_BITMASK |
QuestionModelImpl.SLIDEID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_USERANDSLIDE = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.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_BY_USERANDMODULE =
new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserAndModule",
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_USERANDMODULE =
new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserAndModule",
new String[] { Long.class.getName(), Long.class.getName() },
QuestionModelImpl.USERID_COLUMN_BITMASK |
QuestionModelImpl.MODULEID_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_USERANDMODULE = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserAndModule",
new String[] { Long.class.getName(), Long.class.getName() });
public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, QuestionImpl.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
/**
* Caches the question in the entity cache if it is enabled.
*
* @param question the question
*/
public void cacheResult(Question question) {
EntityCacheUtil.putResult(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionImpl.class, question.getPrimaryKey(), question);
question.resetOriginalValues();
}
/**
* Caches the questions in the entity cache if it is enabled.
*
* @param questions the questions
*/
public void cacheResult(List<Question> questions) {
for (Question question : questions) {
if (EntityCacheUtil.getResult(
QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionImpl.class, question.getPrimaryKey()) == null) {
cacheResult(question);
}
else {
question.resetOriginalValues();
}
}
}
/**
* Clears the cache for all questions.
*
* <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(QuestionImpl.class.getName());
}
EntityCacheUtil.clearCache(QuestionImpl.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 question.
*
* <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(Question question) {
EntityCacheUtil.removeResult(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionImpl.class, question.getPrimaryKey());
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
@Override
public void clearCache(List<Question> questions) {
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
for (Question question : questions) {
EntityCacheUtil.removeResult(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionImpl.class, question.getPrimaryKey());
}
}
/**
* Creates a new question with the primary key. Does not add the question to the database.
*
* @param questionId the primary key for the new question
* @return the new question
*/
public Question create(long questionId) {
Question question = new QuestionImpl();
question.setNew(true);
question.setPrimaryKey(questionId);
return question;
}
/**
* Removes the question with the primary key from the database. Also notifies the appropriate model listeners.
*
* @param questionId the primary key of the question
* @return the question that was removed
* @throws com.ese.ils.beta.NoSuchQuestionException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Question remove(long questionId)
throws NoSuchQuestionException, SystemException {
return remove(Long.valueOf(questionId));
}
/**
* Removes the question with the primary key from the database. Also notifies the appropriate model listeners.
*
* @param primaryKey the primary key of the question
* @return the question that was removed
* @throws com.ese.ils.beta.NoSuchQuestionException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public Question remove(Serializable primaryKey)
throws NoSuchQuestionException, SystemException {
Session session = null;
try {
session = openSession();
Question question = (Question)session.get(QuestionImpl.class,
primaryKey);
if (question == null) {
if (_log.isWarnEnabled()) {
_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
}
throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
primaryKey);
}
return remove(question);
}
catch (NoSuchQuestionException nsee) {
throw nsee;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
@Override
protected Question removeImpl(Question question) throws SystemException {
question = toUnwrappedModel(question);
Session session = null;
try {
session = openSession();
BatchSessionUtil.delete(session, question);
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
clearCache(question);
return question;
}
@Override
public Question updateImpl(com.ese.ils.beta.model.Question question,
boolean merge) throws SystemException {
question = toUnwrappedModel(question);
boolean isNew = question.isNew();
QuestionModelImpl questionModelImpl = (QuestionModelImpl)question;
Session session = null;
try {
session = openSession();
BatchSessionUtil.update(session, question, merge);
question.setNew(false);
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
if (isNew || !QuestionModelImpl.COLUMN_BITMASK_ENABLED) {
FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
}
else {
if ((questionModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(questionModelImpl.getOriginalUserId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USER, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER,
args);
args = new Object[] { Long.valueOf(questionModelImpl.getUserId()) };
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USER, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER,
args);
}
if ((questionModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MODULE.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(questionModelImpl.getOriginalModuleId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MODULE, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MODULE,
args);
args = new Object[] {
Long.valueOf(questionModelImpl.getModuleId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MODULE, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MODULE,
args);
}
if ((questionModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SLIDE.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(questionModelImpl.getOriginalSlideId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SLIDE, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SLIDE,
args);
args = new Object[] { Long.valueOf(questionModelImpl.getSlideId()) };
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SLIDE, args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SLIDE,
args);
}
if ((questionModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDSLIDE.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(questionModelImpl.getOriginalUserId()),
Long.valueOf(questionModelImpl.getOriginalSlideId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERANDSLIDE,
args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDSLIDE,
args);
args = new Object[] {
Long.valueOf(questionModelImpl.getUserId()),
Long.valueOf(questionModelImpl.getSlideId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERANDSLIDE,
args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDSLIDE,
args);
}
if ((questionModelImpl.getColumnBitmask() &
FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDMODULE.getColumnBitmask()) != 0) {
Object[] args = new Object[] {
Long.valueOf(questionModelImpl.getOriginalUserId()),
Long.valueOf(questionModelImpl.getOriginalModuleId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERANDMODULE,
args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDMODULE,
args);
args = new Object[] {
Long.valueOf(questionModelImpl.getUserId()),
Long.valueOf(questionModelImpl.getModuleId())
};
FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERANDMODULE,
args);
FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERANDMODULE,
args);
}
}
EntityCacheUtil.putResult(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionImpl.class, question.getPrimaryKey(), question);
return question;
}
protected Question toUnwrappedModel(Question question) {
if (question instanceof QuestionImpl) {
return question;
}
QuestionImpl questionImpl = new QuestionImpl();
questionImpl.setNew(question.isNew());
questionImpl.setPrimaryKey(question.getPrimaryKey());
questionImpl.setQuestionId(question.getQuestionId());
questionImpl.setUserId(question.getUserId());
questionImpl.setSlideId(question.getSlideId());
questionImpl.setModuleId(question.getModuleId());
questionImpl.setAnswer(question.getAnswer());
questionImpl.setQuestionText(question.getQuestionText());
return questionImpl;
}
/**
* Returns the question 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 question
* @return the question
* @throws com.liferay.portal.NoSuchModelException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public Question findByPrimaryKey(Serializable primaryKey)
throws NoSuchModelException, SystemException {
return findByPrimaryKey(((Long)primaryKey).longValue());
}
/**
* Returns the question with the primary key or throws a {@link com.ese.ils.beta.NoSuchQuestionException} if it could not be found.
*
* @param questionId the primary key of the question
* @return the question
* @throws com.ese.ils.beta.NoSuchQuestionException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByPrimaryKey(long questionId)
throws NoSuchQuestionException, SystemException {
Question question = fetchByPrimaryKey(questionId);
if (question == null) {
if (_log.isWarnEnabled()) {
_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
}
throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
questionId);
}
return question;
}
/**
* Returns the question with the primary key or returns <code>null</code> if it could not be found.
*
* @param primaryKey the primary key of the question
* @return the question, or <code>null</code> if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public Question fetchByPrimaryKey(Serializable primaryKey)
throws SystemException {
return fetchByPrimaryKey(((Long)primaryKey).longValue());
}
/**
* Returns the question with the primary key or returns <code>null</code> if it could not be found.
*
* @param questionId the primary key of the question
* @return the question, or <code>null</code> if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByPrimaryKey(long questionId)
throws SystemException {
Question question = (Question)EntityCacheUtil.getResult(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionImpl.class, questionId);
if (question == _nullQuestion) {
return null;
}
if (question == null) {
Session session = null;
boolean hasException = false;
try {
session = openSession();
question = (Question)session.get(QuestionImpl.class,
Long.valueOf(questionId));
}
catch (Exception e) {
hasException = true;
throw processException(e);
}
finally {
if (question != null) {
cacheResult(question);
}
else if (!hasException) {
EntityCacheUtil.putResult(QuestionModelImpl.ENTITY_CACHE_ENABLED,
QuestionImpl.class, questionId, _nullQuestion);
}
closeSession(session);
}
}
return question;
}
/**
* Returns all the questions where userId = ?.
*
* @param userId the user ID
* @return the matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByUser(long userId) throws SystemException {
return findByUser(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the questions 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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @return the range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByUser(long userId, int start, int end)
throws SystemException {
return findByUser(userId, start, end, null);
}
/**
* Returns an ordered range of all the questions 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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByUser(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_USER;
finderArgs = new Object[] { userId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USER;
finderArgs = new Object[] { userId, start, end, orderByComparator };
}
List<Question> list = (List<Question>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Question question : list) {
if ((userId != question.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_QUESTION_WHERE);
query.append(_FINDER_COLUMN_USER_USERID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else {
query.append(QuestionModelImpl.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<Question>)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 question 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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByUser_First(long userId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchByUser_First(userId, orderByComparator);
if (question != null) {
return question;
}
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 NoSuchQuestionException(msg.toString());
}
/**
* Returns the first question 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 question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByUser_First(long userId,
OrderByComparator orderByComparator) throws SystemException {
List<Question> list = findByUser(userId, 0, 1, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last question 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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByUser_Last(long userId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchByUser_Last(userId, orderByComparator);
if (question != null) {
return question;
}
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 NoSuchQuestionException(msg.toString());
}
/**
* Returns the last question 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 question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByUser_Last(long userId,
OrderByComparator orderByComparator) throws SystemException {
int count = countByUser(userId);
List<Question> list = findByUser(userId, count - 1, count,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the questions before and after the current question in the ordered set where userId = ?.
*
* @param questionId the primary key of the current question
* @param userId the user ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next question
* @throws com.ese.ils.beta.NoSuchQuestionException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Question[] findByUser_PrevAndNext(long questionId, long userId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = findByPrimaryKey(questionId);
Session session = null;
try {
session = openSession();
Question[] array = new QuestionImpl[3];
array[0] = getByUser_PrevAndNext(session, question, userId,
orderByComparator, true);
array[1] = question;
array[2] = getByUser_PrevAndNext(session, question, userId,
orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Question getByUser_PrevAndNext(Session session,
Question question, 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_QUESTION_WHERE);
query.append(_FINDER_COLUMN_USER_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(QuestionModelImpl.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(question);
for (Object value : values) {
qPos.add(value);
}
}
List<Question> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the questions where moduleId = ?.
*
* @param moduleId the module ID
* @return the matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByModule(long moduleId) throws SystemException {
return findByModule(moduleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the questions where 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 moduleId the module ID
* @param start the lower bound of the range of questions
* @param end the upper bound of the range of questions (not inclusive)
* @return the range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByModule(long moduleId, int start, int end)
throws SystemException {
return findByModule(moduleId, start, end, null);
}
/**
* Returns an ordered range of all the questions where 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 moduleId the module ID
* @param start the lower bound of the range of questions
* @param end the upper bound of the range of questions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByModule(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_MODULE;
finderArgs = new Object[] { moduleId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_MODULE;
finderArgs = new Object[] { moduleId, start, end, orderByComparator };
}
List<Question> list = (List<Question>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Question question : list) {
if ((moduleId != question.getModuleId())) {
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_QUESTION_WHERE);
query.append(_FINDER_COLUMN_MODULE_MODULEID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else {
query.append(QuestionModelImpl.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(moduleId);
list = (List<Question>)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 question in the ordered set where moduleId = ?.
*
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByModule_First(long moduleId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchByModule_First(moduleId, orderByComparator);
if (question != null) {
return question;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("moduleId=");
msg.append(moduleId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchQuestionException(msg.toString());
}
/**
* Returns the first question in the ordered set where moduleId = ?.
*
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the first matching question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByModule_First(long moduleId,
OrderByComparator orderByComparator) throws SystemException {
List<Question> list = findByModule(moduleId, 0, 1, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last question in the ordered set where moduleId = ?.
*
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByModule_Last(long moduleId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchByModule_Last(moduleId, orderByComparator);
if (question != null) {
return question;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("moduleId=");
msg.append(moduleId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchQuestionException(msg.toString());
}
/**
* Returns the last question in the ordered set where moduleId = ?.
*
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByModule_Last(long moduleId,
OrderByComparator orderByComparator) throws SystemException {
int count = countByModule(moduleId);
List<Question> list = findByModule(moduleId, count - 1, count,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the questions before and after the current question in the ordered set where moduleId = ?.
*
* @param questionId the primary key of the current question
* @param moduleId the module ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next question
* @throws com.ese.ils.beta.NoSuchQuestionException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Question[] findByModule_PrevAndNext(long questionId, long moduleId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = findByPrimaryKey(questionId);
Session session = null;
try {
session = openSession();
Question[] array = new QuestionImpl[3];
array[0] = getByModule_PrevAndNext(session, question, moduleId,
orderByComparator, true);
array[1] = question;
array[2] = getByModule_PrevAndNext(session, question, moduleId,
orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Question getByModule_PrevAndNext(Session session,
Question question, 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_QUESTION_WHERE);
query.append(_FINDER_COLUMN_MODULE_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(QuestionModelImpl.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(moduleId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(question);
for (Object value : values) {
qPos.add(value);
}
}
List<Question> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the questions where slideId = ?.
*
* @param slideId the slide ID
* @return the matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findBySlide(long slideId) throws SystemException {
return findBySlide(slideId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the questions 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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @return the range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findBySlide(long slideId, int start, int end)
throws SystemException {
return findBySlide(slideId, start, end, null);
}
/**
* Returns an ordered range of all the questions 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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findBySlide(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_SLIDE;
finderArgs = new Object[] { slideId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SLIDE;
finderArgs = new Object[] { slideId, start, end, orderByComparator };
}
List<Question> list = (List<Question>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Question question : list) {
if ((slideId != question.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_QUESTION_WHERE);
query.append(_FINDER_COLUMN_SLIDE_SLIDEID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else {
query.append(QuestionModelImpl.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<Question>)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 question 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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findBySlide_First(long slideId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchBySlide_First(slideId, orderByComparator);
if (question != null) {
return question;
}
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 NoSuchQuestionException(msg.toString());
}
/**
* Returns the first question 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 question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchBySlide_First(long slideId,
OrderByComparator orderByComparator) throws SystemException {
List<Question> list = findBySlide(slideId, 0, 1, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last question 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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findBySlide_Last(long slideId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchBySlide_Last(slideId, orderByComparator);
if (question != null) {
return question;
}
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 NoSuchQuestionException(msg.toString());
}
/**
* Returns the last question 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 question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchBySlide_Last(long slideId,
OrderByComparator orderByComparator) throws SystemException {
int count = countBySlide(slideId);
List<Question> list = findBySlide(slideId, count - 1, count,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the questions before and after the current question in the ordered set where slideId = ?.
*
* @param questionId the primary key of the current question
* @param slideId the slide ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the previous, current, and next question
* @throws com.ese.ils.beta.NoSuchQuestionException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Question[] findBySlide_PrevAndNext(long questionId, long slideId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = findByPrimaryKey(questionId);
Session session = null;
try {
session = openSession();
Question[] array = new QuestionImpl[3];
array[0] = getBySlide_PrevAndNext(session, question, slideId,
orderByComparator, true);
array[1] = question;
array[2] = getBySlide_PrevAndNext(session, question, slideId,
orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Question getBySlide_PrevAndNext(Session session,
Question question, 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_QUESTION_WHERE);
query.append(_FINDER_COLUMN_SLIDE_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(QuestionModelImpl.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(question);
for (Object value : values) {
qPos.add(value);
}
}
List<Question> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the questions where userId = ? and slideId = ?.
*
* @param userId the user ID
* @param slideId the slide ID
* @return the matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByUserAndSlide(long userId, long slideId)
throws SystemException {
return findByUserAndSlide(userId, slideId, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the questions 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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @return the range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> 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 questions 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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> 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<Question> list = (List<Question>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Question question : list) {
if ((userId != question.getUserId()) ||
(slideId != question.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_QUESTION_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(QuestionModelImpl.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<Question>)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 question 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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByUserAndSlide_First(long userId, long slideId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchByUserAndSlide_First(userId, slideId,
orderByComparator);
if (question != null) {
return question;
}
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 NoSuchQuestionException(msg.toString());
}
/**
* Returns the first question 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 question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByUserAndSlide_First(long userId, long slideId,
OrderByComparator orderByComparator) throws SystemException {
List<Question> list = findByUserAndSlide(userId, slideId, 0, 1,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last question 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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByUserAndSlide_Last(long userId, long slideId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchByUserAndSlide_Last(userId, slideId,
orderByComparator);
if (question != null) {
return question;
}
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 NoSuchQuestionException(msg.toString());
}
/**
* Returns the last question 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 question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByUserAndSlide_Last(long userId, long slideId,
OrderByComparator orderByComparator) throws SystemException {
int count = countByUserAndSlide(userId, slideId);
List<Question> list = findByUserAndSlide(userId, slideId, count - 1,
count, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the questions before and after the current question in the ordered set where userId = ? and slideId = ?.
*
* @param questionId the primary key of the current question
* @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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Question[] findByUserAndSlide_PrevAndNext(long questionId,
long userId, long slideId, OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = findByPrimaryKey(questionId);
Session session = null;
try {
session = openSession();
Question[] array = new QuestionImpl[3];
array[0] = getByUserAndSlide_PrevAndNext(session, question, userId,
slideId, orderByComparator, true);
array[1] = question;
array[2] = getByUserAndSlide_PrevAndNext(session, question, userId,
slideId, orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Question getByUserAndSlide_PrevAndNext(Session session,
Question question, 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_QUESTION_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(QuestionModelImpl.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(question);
for (Object value : values) {
qPos.add(value);
}
}
List<Question> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the questions where userId = ? and moduleId = ?.
*
* @param userId the user ID
* @param moduleId the module ID
* @return the matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByUserAndModule(long userId, long moduleId)
throws SystemException {
return findByUserAndModule(userId, moduleId, QueryUtil.ALL_POS,
QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the questions 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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @return the range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByUserAndModule(long userId, long moduleId,
int start, int end) throws SystemException {
return findByUserAndModule(userId, moduleId, start, end, null);
}
/**
* Returns an ordered range of all the questions 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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of matching questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findByUserAndModule(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_USERANDMODULE;
finderArgs = new Object[] { userId, moduleId };
}
else {
finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERANDMODULE;
finderArgs = new Object[] {
userId, moduleId,
start, end, orderByComparator
};
}
List<Question> list = (List<Question>)FinderCacheUtil.getResult(finderPath,
finderArgs, this);
if ((list != null) && !list.isEmpty()) {
for (Question question : list) {
if ((userId != question.getUserId()) ||
(moduleId != question.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_QUESTION_WHERE);
query.append(_FINDER_COLUMN_USERANDMODULE_USERID_2);
query.append(_FINDER_COLUMN_USERANDMODULE_MODULEID_2);
if (orderByComparator != null) {
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
}
else {
query.append(QuestionModelImpl.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<Question>)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 question 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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByUserAndModule_First(long userId, long moduleId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchByUserAndModule_First(userId, moduleId,
orderByComparator);
if (question != null) {
return question;
}
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 NoSuchQuestionException(msg.toString());
}
/**
* Returns the first question 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 question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByUserAndModule_First(long userId, long moduleId,
OrderByComparator orderByComparator) throws SystemException {
List<Question> list = findByUserAndModule(userId, moduleId, 0, 1,
orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the last question 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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question findByUserAndModule_Last(long userId, long moduleId,
OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = fetchByUserAndModule_Last(userId, moduleId,
orderByComparator);
if (question != null) {
return question;
}
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 NoSuchQuestionException(msg.toString());
}
/**
* Returns the last question 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 question, or <code>null</code> if a matching question could not be found
* @throws SystemException if a system exception occurred
*/
public Question fetchByUserAndModule_Last(long userId, long moduleId,
OrderByComparator orderByComparator) throws SystemException {
int count = countByUserAndModule(userId, moduleId);
List<Question> list = findByUserAndModule(userId, moduleId, count - 1,
count, orderByComparator);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
/**
* Returns the questions before and after the current question in the ordered set where userId = ? and moduleId = ?.
*
* @param questionId the primary key of the current question
* @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 question
* @throws com.ese.ils.beta.NoSuchQuestionException if a question with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
public Question[] findByUserAndModule_PrevAndNext(long questionId,
long userId, long moduleId, OrderByComparator orderByComparator)
throws NoSuchQuestionException, SystemException {
Question question = findByPrimaryKey(questionId);
Session session = null;
try {
session = openSession();
Question[] array = new QuestionImpl[3];
array[0] = getByUserAndModule_PrevAndNext(session, question,
userId, moduleId, orderByComparator, true);
array[1] = question;
array[2] = getByUserAndModule_PrevAndNext(session, question,
userId, moduleId, orderByComparator, false);
return array;
}
catch (Exception e) {
throw processException(e);
}
finally {
closeSession(session);
}
}
protected Question getByUserAndModule_PrevAndNext(Session session,
Question question, 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_QUESTION_WHERE);
query.append(_FINDER_COLUMN_USERANDMODULE_USERID_2);
query.append(_FINDER_COLUMN_USERANDMODULE_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(QuestionModelImpl.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(question);
for (Object value : values) {
qPos.add(value);
}
}
List<Question> list = q.list();
if (list.size() == 2) {
return list.get(1);
}
else {
return null;
}
}
/**
* Returns all the questions.
*
* @return the questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findAll() throws SystemException {
return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}
/**
* Returns a range of all the questions.
*
* <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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @return the range of questions
* @throws SystemException if a system exception occurred
*/
public List<Question> findAll(int start, int end) throws SystemException {
return findAll(start, end, null);
}
/**
* Returns an ordered range of all the questions.
*
* <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 questions
* @param end the upper bound of the range of questions (not inclusive)
* @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
* @return the ordered range of questions
* @throws SystemException if a system exception occurred
*/
public List<Question> 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<Question> list = (List<Question>)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_QUESTION);
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
orderByComparator);
sql = query.toString();
}
else {
sql = _SQL_SELECT_QUESTION.concat(QuestionModelImpl.ORDER_BY_JPQL);
}
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
if (orderByComparator == null) {
list = (List<Question>)QueryUtil.list(q, getDialect(),
start, end, false);
Collections.sort(list);
}
else {
list = (List<Question>)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 questions where userId = ? from the database.
*
* @param userId the user ID
* @throws SystemException if a system exception occurred
*/
public void removeByUser(long userId) throws SystemException {
for (Question question : findByUser(userId)) {
remove(question);
}
}
/**
* Removes all the questions where moduleId = ? from the database.
*
* @param moduleId the module ID
* @throws SystemException if a system exception occurred
*/
public void removeByModule(long moduleId) throws SystemException {
for (Question question : findByModule(moduleId)) {
remove(question);
}
}
/**
* Removes all the questions where slideId = ? from the database.
*
* @param slideId the slide ID
* @throws SystemException if a system exception occurred
*/
public void removeBySlide(long slideId) throws SystemException {
for (Question question : findBySlide(slideId)) {
remove(question);
}
}
/**
* Removes all the questions 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 (Question question : findByUserAndSlide(userId, slideId)) {
remove(question);
}
}
/**
* Removes all the questions 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 removeByUserAndModule(long userId, long moduleId)
throws SystemException {
for (Question question : findByUserAndModule(userId, moduleId)) {
remove(question);
}
}
/**
* Removes all the questions from the database.
*
* @throws SystemException if a system exception occurred
*/
public void removeAll() throws SystemException {
for (Question question : findAll()) {
remove(question);
}
}
/**
* Returns the number of questions where userId = ?.
*
* @param userId the user ID
* @return the number of matching questions
* @throws SystemException if a system exception occurred
*/
public int countByUser(long userId) throws SystemException {
Object[] finderArgs = new Object[] { userId };
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USER,
finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(2);
query.append(_SQL_COUNT_QUESTION_WHERE);
query.append(_FINDER_COLUMN_USER_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_USER,
finderArgs, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Returns the number of questions where moduleId = ?.
*
* @param moduleId the module ID
* @return the number of matching questions
* @throws SystemException if a system exception occurred
*/
public int countByModule(long moduleId) throws SystemException {
Object[] finderArgs = new Object[] { moduleId };
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MODULE,
finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(2);
query.append(_SQL_COUNT_QUESTION_WHERE);
query.append(_FINDER_COLUMN_MODULE_MODULEID_2);
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
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_MODULE,
finderArgs, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Returns the number of questions where slideId = ?.
*
* @param slideId the slide ID
* @return the number of matching questions
* @throws SystemException if a system exception occurred
*/
public int countBySlide(long slideId) throws SystemException {
Object[] finderArgs = new Object[] { slideId };
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SLIDE,
finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(2);
query.append(_SQL_COUNT_QUESTION_WHERE);
query.append(_FINDER_COLUMN_SLIDE_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_SLIDE,
finderArgs, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Returns the number of questions where userId = ? and slideId = ?.
*
* @param userId the user ID
* @param slideId the slide ID
* @return the number of matching questions
* @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_QUESTION_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 questions where userId = ? and moduleId = ?.
*
* @param userId the user ID
* @param moduleId the module ID
* @return the number of matching questions
* @throws SystemException if a system exception occurred
*/
public int countByUserAndModule(long userId, long moduleId)
throws SystemException {
Object[] finderArgs = new Object[] { userId, moduleId };
Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERANDMODULE,
finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(3);
query.append(_SQL_COUNT_QUESTION_WHERE);
query.append(_FINDER_COLUMN_USERANDMODULE_USERID_2);
query.append(_FINDER_COLUMN_USERANDMODULE_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_USERANDMODULE,
finderArgs, count);
closeSession(session);
}
}
return count.intValue();
}
/**
* Returns the number of questions.
*
* @return the number of questions
* @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_QUESTION);
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 question persistence.
*/
public void afterPropertiesSet() {
String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
com.liferay.util.service.ServiceProps.get(
"value.object.listener.com.ese.ils.beta.model.Question")));
if (listenerClassNames.length > 0) {
try {
List<ModelListener<Question>> listenersList = new ArrayList<ModelListener<Question>>();
for (String listenerClassName : listenerClassNames) {
listenersList.add((ModelListener<Question>)InstanceFactory.newInstance(
listenerClassName));
}
listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
}
catch (Exception e) {
_log.error(e);
}
}
}
public void destroy() {
EntityCacheUtil.removeCache(QuestionImpl.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_QUESTION = "SELECT question FROM Question question";
private static final String _SQL_SELECT_QUESTION_WHERE = "SELECT question FROM Question question WHERE ";
private static final String _SQL_COUNT_QUESTION = "SELECT COUNT(question) FROM Question question";
private static final String _SQL_COUNT_QUESTION_WHERE = "SELECT COUNT(question) FROM Question question WHERE ";
private static final String _FINDER_COLUMN_USER_USERID_2 = "question.userId = ?";
private static final String _FINDER_COLUMN_MODULE_MODULEID_2 = "question.moduleId = ?";
private static final String _FINDER_COLUMN_SLIDE_SLIDEID_2 = "question.slideId = ?";
private static final String _FINDER_COLUMN_USERANDSLIDE_USERID_2 = "question.userId = ? AND ";
private static final String _FINDER_COLUMN_USERANDSLIDE_SLIDEID_2 = "question.slideId = ?";
private static final String _FINDER_COLUMN_USERANDMODULE_USERID_2 = "question.userId = ? AND ";
private static final String _FINDER_COLUMN_USERANDMODULE_MODULEID_2 = "question.moduleId = ?";
private static final String _ORDER_BY_ENTITY_ALIAS = "question.";
private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Question exists with the primary key ";
private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Question 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(QuestionPersistenceImpl.class);
private static Question _nullQuestion = new QuestionImpl() {
@Override
public Object clone() {
return this;
}
@Override
public CacheModel<Question> toCacheModel() {
return _nullQuestionCacheModel;
}
};
private static CacheModel<Question> _nullQuestionCacheModel = new CacheModel<Question>() {
public Question toEntityModel() {
return _nullQuestion;
}
};
}