本文整理汇总了Java中org.hibernate.SQLQuery.setFirstResult方法的典型用法代码示例。如果您正苦于以下问题:Java SQLQuery.setFirstResult方法的具体用法?Java SQLQuery.setFirstResult怎么用?Java SQLQuery.setFirstResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.SQLQuery
的用法示例。
在下文中一共展示了SQLQuery.setFirstResult方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pageBySql
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
/**
* 返回指定对象数据集合,查询字段名或者别名与指定对象字段一致。
*/
@SuppressWarnings({"unchecked"})
public <T> Pagination<T> pageBySql(Class<T> clazz, final CharSequence queryString,
final Object[] values, int pageIndex, int pageSize) {
SQLQuery sqlQuery = getSession().createSQLQuery(queryString.toString());
if ((pageSize > 0) && (pageIndex > 0)) {
sqlQuery.setFirstResult((pageIndex - 1) * pageSize);
sqlQuery.setMaxResults(pageIndex * pageSize);
}
setParameter(sqlQuery, values);
AddScalar.addSclar(sqlQuery, clazz);
List<T> items = sqlQuery.list();
BigInteger rowsCount = (BigInteger) getSingleColumnBySql(getCountStr(queryString.toString()), values);
Pagination<T> pagination = new Pagination((long) pageIndex, (long) pageSize, rowsCount.longValue());
pagination.setItems(items);
return pagination;
}
示例2: findBySql
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
public <T> List<T> findBySql(String sql, Object[] vals, int from_id, int len) {
Session session = hibernateTemplate.getSessionFactory().openSession();
org.hibernate.Transaction tx = session.beginTransaction();
SQLQuery query = session.createSQLQuery(sql);
if(vals != null) {
for(int i=0;i<vals.length;i++) {
if(vals[i] instanceof Integer) {
query.setInteger(i, (Integer) vals[i]);
} else {
query.setString(i, vals[i].toString());
}
}
}
if(len>0) {
query.setFirstResult(from_id);
query.setMaxResults(len-1);
}
try {
tx.commit();
return query.list();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
return null;
} finally {
session.close();
}
}
示例3: getPagedUsersBySession
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<AssessmentUserDTO> getPagedUsersBySession(Long sessionId, int page, int size, String sortBy,
String sortOrder, String searchString, IUserManagementService userManagementService) {
String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id");
StringBuilder bldr = new StringBuilder(LOAD_USERS_ORDERED_BY_SESSION_SELECT)
.append(portraitStrings[0])
.append(LOAD_USERS_ORDERED_BY_SESSION_FROM)
.append(portraitStrings[1])
.append(LOAD_USERS_ORDERED_BY_SESSION_JOIN);
if ( "total".equalsIgnoreCase(sortBy) )
bldr.append(LOAD_USERS_ORDERED_ORDER_BY_TOTAL);
else
bldr.append(LOAD_USERS_ORDERED_ORDER_BY_NAME);
bldr.append(sortOrder);
SQLQuery query = getSession().createSQLQuery(bldr.toString());
query.setLong("sessionId", sessionId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
List<Object[]> list = query.list();
ArrayList<AssessmentUserDTO> userDtos = new ArrayList<AssessmentUserDTO>();
if (list != null && list.size() > 0) {
for (Object[] element : list) {
Long userId = ((Number) element[0]).longValue();
String firstName = (String) element[1];
String lastName = (String) element[2];
String login = (String) element[3];
float grade = element[4] == null ? 0 : ((Number) element[4]).floatValue();
Long portraitId = element[5] == null ? null : ((Number) element[5]).longValue();
AssessmentUserDTO userDto = new AssessmentUserDTO();
userDto.setUserId(userId);
userDto.setFirstName(firstName);
userDto.setLastName(lastName);
userDto.setLogin(login);
userDto.setGrade(grade);
userDto.setPortraitId(portraitId);
userDtos.add(userDto);
}
}
return userDtos;
}
示例4: getPagedUsersBySessionAndQuestion
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<AssessmentUserDTO> getPagedUsersBySessionAndQuestion(Long sessionId, Long questionUid, int page,
int size, String sortBy, String sortOrder, String searchString, IUserManagementService userManagementService) {
String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id");
StringBuilder bldr = new StringBuilder(LOAD_USERS_ORDERED_BY_SESSION_QUESTION_SELECT)
.append(portraitStrings[0])
.append(LOAD_USERS_ORDERED_BY_SESSION_QUESTION_FROM)
.append(portraitStrings[1])
.append(LOAD_USERS_ORDERED_BY_SESSION_QUESTION_JOIN);
if ( "grade".equalsIgnoreCase(sortBy) )
bldr.append(LOAD_USERS_ORDERED_ORDER_BY_RESULT);
else
bldr.append(LOAD_USERS_ORDERED_ORDER_BY_NAME);
bldr.append(sortOrder);
SQLQuery query = getSession().createSQLQuery(bldr.toString());
query.setLong("sessionId", sessionId);
query.setLong("questionUid", questionUid);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
List<Object[]> list = query.list();
ArrayList<AssessmentUserDTO> userDtos = new ArrayList<AssessmentUserDTO>();
if (list != null && list.size() > 0) {
for (Object[] element : list) {
Long questionResultUid = ((Number) element[0]).longValue();
String firstName = (String) element[1];
String lastName = (String) element[2];
String login = (String) element[3];
float grade = element[4] == null ? 0 : ((Number) element[4]).floatValue();
Long portraitId = element[5] == null ? null : ((Number) element[5]).longValue();
AssessmentUserDTO userDto = new AssessmentUserDTO();
userDto.setQuestionResultUid(questionResultUid);
;
userDto.setFirstName(firstName);
userDto.setLastName(lastName);
userDto.setLogin(login);
userDto.setGrade(grade);
userDto.setPortraitId(portraitId);
userDtos.add(userDto);
}
}
return userDtos;
}
示例5: getPagedUsersBySession
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<McUserMarkDTO> getPagedUsersBySession(Long sessionId, int page, int size, String sortBy,
String sortOrder, String searchString, IUserManagementService userManagementService) {
String[] portraitStrings = userManagementService.getPortraitSQL("user.que_usr_id");
StringBuilder bldr = new StringBuilder(LOAD_USERS_SELECT)
.append(portraitStrings[0])
.append(LOAD_USERS_FROM)
.append(portraitStrings[1])
.append(LOAD_USERS_JOINWHERE)
.append(sortOrder);
SQLQuery query = getSession().createSQLQuery(bldr.toString());
query.setLong("sessionId", sessionId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setString("sortBy", sortBy);
query.setFirstResult(page * size);
query.setMaxResults(size);
List<Object[]> list = query.list();
ArrayList<McUserMarkDTO> userDtos = new ArrayList<McUserMarkDTO>();
if (list != null && list.size() > 0) {
for (Object[] element : list) {
Long userUid = ((Number) element[0]).longValue();
Long userId = ((Number) element[1]).longValue();
String fullName = (String) element[2];
Integer totalMark = element[3] == null ? 0 : ((Number) element[3]).intValue();
Long portraitId = element[4] == null ? null : ((Number) element[4]).longValue();
McUserMarkDTO userDto = new McUserMarkDTO();
userDto.setQueUsrId(userUid.toString());
userDto.setUserId(userId.toString());
userDto.setFullName(fullName);
userDto.setTotalMark(new Long(totalMark));
userDto.setPortraitId(portraitId==null ? null : portraitId.toString());
userDtos.add(userDto);
}
}
return userDtos;
}
示例6: getPagedUsersBySession
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Collection<TaskListUserDTO> getPagedUsersBySession(Long sessionId, int page, int size, String sortBy,
String sortOrder, String searchString, IUserManagementService userManagementService) {
String[] portraitStrings = userManagementService.getPortraitSQL("user.user_id");
StringBuilder bldr = new StringBuilder(LOAD_USERS_SELECT)
.append(portraitStrings[0])
.append(LOAD_USERS_FROM)
.append(portraitStrings[1])
.append(LOAD_USERS_JOINS)
.append(sortOrder);
SQLQuery query = getSession().createSQLQuery(bldr.toString());
query.setLong("sessionId", sessionId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
List<Object[]> list = query.list();
//group by userId as long as it returns all completed visitLogs for each user
HashMap<Long, TaskListUserDTO> userIdToUserDto = new LinkedHashMap<Long, TaskListUserDTO>();
if (list != null && list.size() > 0) {
for (Object[] element : list) {
Long userId = ((Number) element[0]).longValue();
String fullName = (String) element[1];
boolean isVerifiedByMonitor = element[2] == null ? false : (Boolean) element[2];
Long completedTaskUid = element[3] == null ? 0 : ((Number) element[3]).longValue();
Long portraitId = element[4] == null ? null : ((Number) element[4]).longValue();
TaskListUserDTO userDto = (userIdToUserDto.get(userId) == null) ? new TaskListUserDTO()
: userIdToUserDto.get(userId);
userDto.setUserId(userId);
userDto.setFullName(fullName);
userDto.setVerifiedByMonitor(isVerifiedByMonitor);
userDto.getCompletedTaskUids().add(completedTaskUid);
userDto.setPortraitId(portraitId);
userIdToUserDto.put(userId, userDto);
}
}
return userIdToUserDto.values();
}
示例7: getPagedUsersBySessionAndItem
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@Override
public Collection<TaskListUserDTO> getPagedUsersBySessionAndItem(Long sessionId, Long taskListItemUid, int page,
int size, String sortBy, String sortOrder, String searchString) {
String LOAD_USERS = "SELECT user.user_id, CONCAT(user.last_name, ' ', user.first_name), visitLog.complete, visitLog.access_date"
+ " FROM tl_latask10_user user" + " INNER JOIN tl_latask10_session session"
+ " ON user.session_uid=session.uid" +
" LEFT OUTER JOIN tl_latask10_item_log visitLog " + " ON visitLog.user_uid = user.uid"
+ " AND visitLog.taskList_item_uid = :taskListItemUid" +
" WHERE session.session_id = :sessionId "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ " ORDER BY " + " CASE "
+ " WHEN :sortBy='userName' THEN CONCAT(user.last_name, ' ', user.first_name) "
+ " WHEN :sortBy='completed' THEN visitLog.complete "
+ " WHEN :sortBy='accessDate' THEN visitLog.access_date " + " END " + sortOrder;
SQLQuery query = getSession().createSQLQuery(LOAD_USERS);
query.setLong("sessionId", sessionId);
query.setLong("taskListItemUid", taskListItemUid);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setString("sortBy", sortBy);
query.setFirstResult(page * size);
query.setMaxResults(size);
List<Object[]> list = query.list();
Collection<TaskListUserDTO> userDtos = new LinkedList<TaskListUserDTO>();
if (list != null && list.size() > 0) {
for (Object[] element : list) {
Long userId = ((Number) element[0]).longValue();
String fullName = (String) element[1];
boolean isCompleted = element[2] == null ? false : new Boolean(((Byte) element[2]).intValue() == 1);
Date accessDate = element[3] == null ? null : new Date(((Timestamp) element[3]).getTime());
TaskListUserDTO userDto = new TaskListUserDTO();
userDto.setUserId(userId);
userDto.setFullName(fullName);
userDto.setCompleted(isCompleted);
userDto.setAccessDate(accessDate);
;
userDtos.add(userDto);
}
}
return userDtos;
}
示例8: getUsersByLesson
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@Override
public List<User> getUsersByLesson(Long lessonId, int page, int size, String sortBy, String sortOrder,
String searchString) {
final String LOAD_LEARNERS_ORDERED_BY_NAME = "SELECT DISTINCT user.* "
+ " FROM lams_lesson lesson, lams_group g, lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id " + " WHERE lesson.lesson_id = :lessonId "
+ " AND lesson.class_grouping_id=g.grouping_id " + " AND ug.group_id=g.group_id "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ "ORDER BY CONCAT(user.last_name, ' ', user.first_name) " + sortOrder;
//when :sortBy='timeTaken'
final String LOAD_LEARNERS_ORDERED_BY_TIME_TAKEN = "SELECT DISTINCT user.* "
+ " FROM lams_lesson lesson, lams_group g, lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id "
+ " LEFT OUTER JOIN lams_learner_progress progress "
+ " ON progress.user_id=user.user_id AND progress.lesson_id=:lessonId "
+ " WHERE lesson.lesson_id = :lessonId " + " AND lesson.class_grouping_id=g.grouping_id "
+ " AND ug.group_id=g.group_id "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ "ORDER BY TIMEDIFF(progress.finish_date_time, progress.start_date_time) " + sortOrder;
//when :sortBy='mark'
final String LOAD_LEARNERS_ORDERED_BY_MARK = "SELECT DISTINCT user.* "
+ " FROM lams_lesson lesson, lams_group g, lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id "
+ " LEFT OUTER JOIN lams_gradebook_user_lesson gradebookUserLesson "
+ " ON user.user_id=gradebookUserLesson.user_id AND gradebookUserLesson.lesson_id =:lessonId "
+ " WHERE lesson.lesson_id = :lessonId " + " AND lesson.class_grouping_id=g.grouping_id "
+ " AND ug.group_id=g.group_id "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ " ORDER BY gradebookUserLesson.mark " + sortOrder;
//when :sortBy='feedback'
final String LOAD_LEARNERS_ORDERED_BY_FEEDBACK = "SELECT DISTINCT user.* "
+ " FROM lams_lesson lesson, lams_group g, lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id "
+ " LEFT OUTER JOIN lams_gradebook_user_lesson gradebookUserLesson "
+ " ON user.user_id=gradebookUserLesson.user_id AND gradebookUserLesson.lesson_id =:lessonId "
+ " WHERE lesson.lesson_id = :lessonId " + " AND lesson.class_grouping_id=g.grouping_id "
+ " AND ug.group_id=g.group_id "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ " ORDER BY gradebookUserLesson.feedback " + sortOrder;
String queryString;
if (sortBy.equals("timeTaken")) {
queryString = LOAD_LEARNERS_ORDERED_BY_TIME_TAKEN;
} else if (sortBy.equals("mark")) {
queryString = LOAD_LEARNERS_ORDERED_BY_MARK;
} else if (sortBy.equals("feedback")) {
queryString = LOAD_LEARNERS_ORDERED_BY_FEEDBACK;
} else {
queryString = LOAD_LEARNERS_ORDERED_BY_NAME;
}
SQLQuery query = getSession().createSQLQuery(queryString);
query.addEntity(User.class);
query.setLong("lessonId", lessonId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
return query.list();
}
示例9: getUsersByActivity
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@Override
public List<User> getUsersByActivity(Long lessonId, Long activityId, int page, int size, String sortBy,
String sortOrder, String searchString) {
final String LOAD_LEARNERS_ORDERED_BY_NAME = "SELECT DISTINCT user.* "
+ " FROM lams_lesson lesson, lams_group g, lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id " + " WHERE lesson.lesson_id = :lessonId "
+ " AND lesson.class_grouping_id=g.grouping_id " + " AND ug.group_id=g.group_id "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ " ORDER BY CONCAT(user.last_name, ' ', user.first_name) " + sortOrder;
//when :sortBy='timeTaken'
final String LOAD_LEARNERS_ORDERED_BY_TIME_TAKEN_ACTIVITY = "SELECT DISTINCT user.* "
+ " FROM lams_lesson lesson, lams_group g, lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id "
+ " LEFT OUTER JOIN lams_learner_progress progress "
+ " INNER JOIN lams_progress_completed completedActivityProgress "
+ " ON completedActivityProgress.learner_progress_id=progress.learner_progress_id "
+ " AND completedActivityProgress.activity_id=:activityId " + " ON progress.user_id=user.user_id "
+ " WHERE lesson.lesson_id = :lessonId " + " AND lesson.class_grouping_id=g.grouping_id "
+ " AND ug.group_id=g.group_id "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ "ORDER BY TIMEDIFF(completedActivityProgress.completed_date_time, completedActivityProgress.start_date_time) "
+ sortOrder;
//when :sortBy='mark'
final String LOAD_LEARNERS_ORDERED_BY_MARK_ACTIVITY = "SELECT DISTINCT user.* "
+ " FROM lams_lesson lesson, lams_group g, lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id "
+ " LEFT OUTER JOIN lams_gradebook_user_activity gradebookUserActivity "
+ " ON user.user_id=gradebookUserActivity.user_id AND gradebookUserActivity.activity_id =:activityId "
+ " WHERE lesson.lesson_id = :lessonId " + " AND lesson.class_grouping_id=g.grouping_id "
+ " AND ug.group_id=g.group_id "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ "ORDER BY gradebookUserActivity.mark " + sortOrder;
String queryString;
if (sortBy.equals("timeTaken")) {
queryString = LOAD_LEARNERS_ORDERED_BY_TIME_TAKEN_ACTIVITY;
} else if (sortBy.equals("mark")) {
queryString = LOAD_LEARNERS_ORDERED_BY_MARK_ACTIVITY;
} else {
queryString = LOAD_LEARNERS_ORDERED_BY_NAME;
}
SQLQuery query = getSession().createSQLQuery(queryString);
query.addEntity(User.class);
query.setLong("lessonId", lessonId);
if (sortBy.equals("timeTaken") || sortBy.equals("mark")) {
query.setLong("activityId", activityId);
}
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
return query.list();
}
示例10: getUsersByGroup
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@Override
public List<User> getUsersByGroup(Long lessonId, Long activityId, Long groupId, int page, int size, String sortBy,
String sortOrder, String searchString) {
final String LOAD_LEARNERS_ORDERED_BY_NAME = "SELECT DISTINCT user.* " + " FROM lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id " + " WHERE ug.group_id=:groupId "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ " ORDER BY CONCAT(user.last_name, ' ', user.first_name) " + sortOrder;
//when :sortBy='timeTaken'
final String LOAD_LEARNERS_ORDERED_BY_TIME_TAKEN_GROUP = "SELECT DISTINCT user.* " + " FROM lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id "
+ " LEFT OUTER JOIN lams_learner_progress progress "
+ " INNER JOIN lams_progress_completed completedActivityProgress "
+ " ON completedActivityProgress.learner_progress_id=progress.learner_progress_id "
+ " AND completedActivityProgress.activity_id=:activityId " + " ON progress.user_id=user.user_id "
+ " WHERE ug.group_id=:groupId "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ " ORDER BY TIMEDIFF(completedActivityProgress.completed_date_time, completedActivityProgress.start_date_time) "
+ sortOrder;
//when :sortBy='mark'
final String LOAD_LEARNERS_ORDERED_BY_MARK_GROUP = "SELECT DISTINCT user.* " + " FROM lams_user_group ug "
+ " INNER JOIN lams_user user ON ug.user_id=user.user_id "
+ " LEFT OUTER JOIN lams_gradebook_user_activity gradebookUserActivity "
+ " ON user.user_id=gradebookUserActivity.user_id AND gradebookUserActivity.activity_id =:activityId "
+ " WHERE ug.group_id=:groupId "
+ " AND (CONCAT(user.last_name, ' ', user.first_name) LIKE CONCAT('%', :searchString, '%')) "
+ "ORDER BY gradebookUserActivity.mark " + sortOrder;
String queryString;
if (sortBy.equals("timeTaken")) {
queryString = LOAD_LEARNERS_ORDERED_BY_TIME_TAKEN_GROUP;
} else if (sortBy.equals("mark")) {
queryString = LOAD_LEARNERS_ORDERED_BY_MARK_GROUP;
} else {
queryString = LOAD_LEARNERS_ORDERED_BY_NAME;
}
SQLQuery query = getSession().createSQLQuery(queryString);
query.addEntity(User.class);
if (sortBy.equals("timeTaken") || sortBy.equals("mark")) {
query.setLong("activityId", activityId);
}
query.setLong("groupId", groupId);
// support for custom search from a toolbar
searchString = searchString == null ? "" : searchString;
query.setString("searchString", searchString);
query.setFirstResult(page * size);
query.setMaxResults(size);
return query.list();
}
示例11: createSearchQuery
import org.hibernate.SQLQuery; //导入方法依赖的package包/类
public static Query createSearchQuery(CriteriaInstantVO criteriaInstantVO, DBModule module, PSFVO psf, SessionFactory sessionFactory,
CriterionTieDao criterionTieDao, CriterionPropertyDao criterionPropertyDao, CriterionRestrictionDao criterionRestrictionDao) throws Exception {
ArrayList<QueryParameterValue> queryValues = new ArrayList<QueryParameterValue>();
HashMap<NamedParameterValues, Object> namedParameterValuesCache = new HashMap<NamedParameterValues, Object>();
StringBuilder sqlQuery = createSQLSetStatement(criteriaInstantVO, module, psf, sessionFactory, queryValues,
createCriterionTieMap(criterionTieDao),
createCriterionTieNameMap(criterionTieDao),
createCriterionPropertyMap(module, criterionPropertyDao),
// null, // createCriterionPropertyNameMap(module, criterionPropertyDao),
createCriterionRestrictionMap(criterionRestrictionDao),
null); // createCriterionRestrictionNameMap(criterionRestrictionDao));
Class rootEntityClass = getRootEntityClass(module);
SQLQuery query;
if (psf != null) {
if (psf.getUpdateRowCount()) {
StringBuilder countStatement = new StringBuilder("select count(*) from (");
countStatement.append(sqlQuery);
countStatement.append(") as resultset");
Query countQuery = sessionFactory.getCurrentSession().createSQLQuery(countStatement.toString());
setQueryValues(countQuery, queryValues, namedParameterValuesCache);
psf.setRowCount(new Long(countQuery.uniqueResult().toString()));
}
String sortField = psf.getSortField();
if (sortField != null && sortField.length() > 0) {
// http://weblogs.sqlteam.com/jeffs/archive/2007/12/13/select-distinct-order-by-error.aspx
sqlQuery.append(" order by ");
sqlQuery.append(getPropertyColumnName(rootEntityClass, sortField, sessionFactory)); // sessionFactory));
if (psf.getSortOrder()) {
sqlQuery.append(" asc");
} else {
sqlQuery.append(" desc");
}
}
query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery.toString());
if (psf.getFirst() != null) {
query.setFirstResult(psf.getFirst());
}
if (psf.getPageSize() != null) {
query.setMaxResults(psf.getPageSize());
}
} else {
query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery.toString());
}
setQueryValues(query, queryValues, namedParameterValuesCache);
query.addEntity(rootEntityClass);
return query;
}