当前位置: 首页>>代码示例>>Java>>正文


Java SQLQuery.setString方法代码示例

本文整理汇总了Java中org.hibernate.SQLQuery.setString方法的典型用法代码示例。如果您正苦于以下问题:Java SQLQuery.setString方法的具体用法?Java SQLQuery.setString怎么用?Java SQLQuery.setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.SQLQuery的用法示例。


在下文中一共展示了SQLQuery.setString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: delete

import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@Override
   public void delete(Object object) {
// remove references to the removed page
WikiPage removedWikiPage = (WikiPage) object;
String title = removedWikiPage.getTitle();
String escapedTitle = WikiPageDTO.javaScriptEscape(title);
String codeToReplace = WikiPageDAO.CHANGE_WIKI_JAVASCRIPT_METHOD.replace("?", escapedTitle);
String replacementCode = "#";

SQLQuery query = getSessionFactory().getCurrentSession().createSQLQuery(REMOVE_WIKI_REFERENCES);
query.setString(0, codeToReplace);
query.setString(1, replacementCode);
query.setLong(2, removedWikiPage.getParentWiki().getUid());

super.delete(object);
query.executeUpdate();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:WikiPageDAO.java

示例2: updateBySql

import org.hibernate.SQLQuery; //导入方法依赖的package包/类
public void updateBySql(String sql, Object[] vals) {
	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());
			}
		}
	}
	query.executeUpdate();
	
	try {
		tx.commit();
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	}
	session.close(); 
}
 
开发者ID:lrxzl,项目名称:djpt,代码行数:26,代码来源:DaoImpl.java

示例3: getList

import org.hibernate.SQLQuery; //导入方法依赖的package包/类
@Override
public List<Object[]> getList() {
	//create the session
	Session ses=null;
	//get the session
	ses=HibernateUtil.getSession();
		//create the list of class object
		List<Object[]> list=null;
		//create the named parameterised the query
		SQLQuery query=ses.createSQLQuery("select PRODID,PRODNAME from PRODUCT where price>:price");
		//pass the parameter to query
		query.setString("price", "500");
	//add scalar to query
	query.addScalar("PRODID", StandardBasicTypes.INTEGER);
	query.addScalar("PRODNAME", StandardBasicTypes.STRING);
		//execute the query
		list=query.list();
			//close the session
		HibernateUtil.closeSession(ses);
		//return the list
		return list;
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Native_SQL_Scalar_Using_DAO_Using_MAVEN,代码行数:23,代码来源:DAO_IMPL.java

示例4: 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(); 
	}
	
}
 
开发者ID:lrxzl,项目名称:djpt,代码行数:33,代码来源:DaoImpl.java

示例5: quOrderByIdAdd1

import org.hibernate.SQLQuery; //导入方法依赖的package包/类
/**
 * 更新orderbyId
 * 属性 belongId所有题目,只要大于等于orderById+1
 * @param belongId
 * @param orderById
 */
private void quOrderByIdAdd1(String belongId,Integer orderById){
	if(belongId!=null && !"".equals(belongId)){
		String sql="update t_question set order_by_id=order_by_id+1 where belong_id=? and order_by_id>=?";
		//更新排序号
		SQLQuery query=this.getSession().createSQLQuery(sql);
		query.setString(0, belongId);
		query.setInteger(1, orderById);
		query.executeUpdate();
	}
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:17,代码来源:QuestionDaoImpl.java

示例6: quOrderByIdDel1

import org.hibernate.SQLQuery; //导入方法依赖的package包/类
public void quOrderByIdDel1(String belongId,Integer orderById){
	if(belongId!=null && !"".equals(belongId)){
		String sql="update t_question set order_by_id=order_by_id-1 where belong_id=? and order_by_id>=?";
		//更新排序号
		SQLQuery query=this.getSession().createSQLQuery(sql);
		query.setString(0, belongId);
		query.setInteger(1, orderById);
		query.executeUpdate();
	}
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:11,代码来源:QuestionDaoImpl.java

示例7: quOrderByIdDel1

import org.hibernate.SQLQuery; //导入方法依赖的package包/类
public void quOrderByIdDel1(String quId,Integer orderById){
	if(quId!=null && !"".equals(quId)){
		String sql="update t_qu_radio set order_by_id=order_by_id-1 where qu_id=? and order_by_id>=?";
		//更新排序号
		SQLQuery query=this.getSession().createSQLQuery(sql);
		query.setString(0, quId);
		query.setInteger(1, orderById);
		query.executeUpdate();
	}
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:11,代码来源:QuRadioDaoImpl.java

示例8: 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;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:53,代码来源:AssessmentUserDAOHibernate.java

示例9: 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;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:55,代码来源:AssessmentUserDAOHibernate.java

示例10: 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;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:48,代码来源:McUserDAO.java

示例11: 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();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:50,代码来源:TaskListUserDAOHibernate.java

示例12: 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;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:52,代码来源:TaskListUserDAOHibernate.java

示例13: 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();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:66,代码来源:GradebookDAO.java

示例14: 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();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:59,代码来源:GradebookDAO.java

示例15: 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();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:53,代码来源:GradebookDAO.java


注:本文中的org.hibernate.SQLQuery.setString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。