本文整理汇总了Java中org.springframework.orm.hibernate4.HibernateCallback类的典型用法代码示例。如果您正苦于以下问题:Java HibernateCallback类的具体用法?Java HibernateCallback怎么用?Java HibernateCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HibernateCallback类属于org.springframework.orm.hibernate4包,在下文中一共展示了HibernateCallback类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: queryList
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* 不分页查询数据
* @param filters Map<String, Object>查询参数和条件数据<br />
* 需要重写queryParam(Criteria criteria)方法
* @return List<E>
*/
public List<E> queryList(final Map filters)
{
return (List<E>) getHibernateTemplate().execute(new HibernateCallback()
{
public List<E> doInHibernate(Session session) throws HibernateException// , SQLException
{
Criteria criteria = session.createCriteria(getEntityClass());
queryParam(filters, criteria);
return criteria.list();
}
});
// Criteria criteria = createCriteria();
// if (pageRequest.getFilters() instanceof Map)
// {
// queryParam((Map)pageRequest.getFilters(), criteria);
// }
// return criteria.list();
}
开发者ID:skeychen,项目名称:dswork,代码行数:25,代码来源:HibernateBaseDao.java
示例2: queryPage
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* 分页查询数据
* @param pageRequest <Map>PageRequest.getFilters()查询参数和条件数据<br />
* 需要重写queryParam(Criteria criteria)方法
* @return Page
*/
public Page queryPage(final PageRequest pageRequest)
{
return (Page)getHibernateTemplate().execute(new HibernateCallback()
{
public Page doInHibernate(Session session) throws HibernateException//, SQLException
{
Criteria criteria = session.createCriteria(getEntityClass());
if (pageRequest.getFilters() instanceof Map)
{
queryParam((Map)pageRequest.getFilters(), criteria);
}
return queryPage(criteria, pageRequest);
}
});
// Criteria criteria = createCriteria();
// if (pageRequest.getFilters() instanceof Map)
// {
// queryParam((Map)pageRequest.getFilters(), criteria);
// }
// return queryPage(criteria, pageRequest);
}
开发者ID:skeychen,项目名称:dswork,代码行数:28,代码来源:HibernateBaseDao.java
示例3: createQuery
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* 创建Query对象
* @param hql HQL语句
* @param values 可变条件
* @return Query
*/
protected Query createQuery(final String hql, final Object... values)
{
Assert.hasText(hql);
Query query = (Query)getHibernateTemplate().execute(new HibernateCallback()
{
public Query doInHibernate(Session session) throws HibernateException//, SQLException
{
return session.createQuery(hql);
}
});
for(int i = 0; i < values.length; i++)
{
query.setParameter(i, values[i]);
}
return query;
}
开发者ID:skeychen,项目名称:dswork,代码行数:23,代码来源:HibernateDao.java
示例4: createCriteria
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* 创建Criteria对象
* @param criterions 可变条件Restrictions<br />
* criteria.add(Restrictions.eq(propertyName, value));
* @return Criteria
*/
protected Criteria createCriteria(Criterion... criterions)
{
//final Class _class = getEntityClass();
Criteria criteria = (Criteria)getHibernateTemplate().execute(new HibernateCallback()
{
public Criteria doInHibernate(Session session) throws HibernateException//, SQLException
{
//return session.createCriteria(_class);
return session.createCriteria(getEntityClass());
}
});// QBC方式
for(Criterion c : criterions)
{
criteria.add(c);
}
return criteria;
}
开发者ID:skeychen,项目名称:dswork,代码行数:24,代码来源:HibernateDao.java
示例5: findByPage
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* ʹ��hql �����з�ҳ��ѯ����
* @param hql ��Ҫ��ѯ��hql���
* @param pageNo ��ѯ��pageNoҳ�ļ�¼
* @param pageSize ÿҳ��Ҫ��ʾ�ļ�¼��
* @return ��ǰҳ�����м�¼
*/
@SuppressWarnings("unchecked")
protected List<T> findByPage(final String hql,
final int pageNo, final int pageSize)
{
// ͨ��һ��HibernateCallback������ִ�в�ѯ
List<T> list = getHibernateTemplate()
.execute(new HibernateCallback<List<T>>()
{
// ʵ��HibernateCallback�ӿڱ���ʵ�ֵķ���
public List<T> doInHibernate(Session session)
{
// ִ��Hibernate��ҳ��ѯ
List<T> result = session.createQuery(hql)
.setFirstResult((pageNo - 1) * pageSize)
.setMaxResults(pageSize)
.list();
return result;
}
});
return list;
}
开发者ID:wolfogre,项目名称:CodesOfLightweightJavaEE,代码行数:29,代码来源:BaseDaoHibernate3.java
示例6: getLastSubmittedAssessmentGradingList
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
public List getLastSubmittedAssessmentGradingList(final Long publishedAssessmentId) {
final HibernateCallback<List<AssessmentGradingData>> hcb = session -> {
Query q = session.createQuery(
"select a from AssessmentGradingData a left join fetch a.assessmentGradingAttachmentSet " +
"where a.publishedAssessmentId = :id and a.forGrade = :forgrade order by a.agentId asc, a.submittedDate desc");
q.setLong("id", publishedAssessmentId);
q.setBoolean("forgrade", true);
return q.list();
};
List<AssessmentGradingData> assessmentGradings = getHibernateTemplate().execute(hcb);
return new ArrayList<>(assessmentGradings.stream()
.collect(Collectors.toMap(AssessmentGradingData::getAgentId, p -> p, (p, q) -> p))
.values());
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:AssessmentGradingFacadeQueries.java
示例7: getPeerAssessmentItems
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
public List<PeerAssessmentItem> getPeerAssessmentItems(final String assignmentId, final String assessorUserId, Integer scaledFactor) {
List<PeerAssessmentItem> listPeerAssessmentItem = new ArrayList<>();
if (assignmentId == null || assessorUserId == null) {
//return an empty list
return listPeerAssessmentItem;
}
HibernateCallback<List<PeerAssessmentItem>> hcb = session -> {
Query q = session.getNamedQuery("findPeerAssessmentItemsByUserAndAssignment");
q.setParameter("assignmentId", assignmentId);
q.setParameter("assessorUserId", assessorUserId);
return q.list();
};
listPeerAssessmentItem = getHibernateTemplate().execute(hcb);
for (PeerAssessmentItem item : listPeerAssessmentItem) {
item.setScaledFactor(scaledFactor);
}
return listPeerAssessmentItem;
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:22,代码来源:AssignmentPeerAssessmentServiceImpl.java
示例8: swapSyllabusDataPositions
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* swapSyllabusDataPositions swaps positions for two SyllabusData objects
* @param syllabusItem
* @param d1
* @param d2
*/
public void swapSyllabusDataPositions(final SyllabusItem syllabusItem, final SyllabusData d1, final SyllabusData d2)
{
if (syllabusItem == null || d1 == null || d2 == null)
{
throw new IllegalArgumentException("Null Argument");
}
else
{
HibernateCallback hcb = session -> {
// load objects from hibernate
SyllabusData data1 = (SyllabusData) session.get(SyllabusDataImpl.class, d1.getSyllabusId());
SyllabusData data2 = (SyllabusData) session.get(SyllabusDataImpl.class, d2.getSyllabusId());
Integer temp = data1.getPosition();
data1.setPosition(data2.getPosition());
data2.setPosition(temp);
return null;
};
getHibernateTemplate().execute(hcb);
}
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:29,代码来源:SyllabusManagerImpl.java
示例9: getSyllabusItemByUserAndContextIds
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* getSyllabusItemByUserAndContextIds finds a SyllabusItem
* @param userId
* @param contextId
* @return SyllabusItem
*
*/
public SyllabusItem getSyllabusItemByUserAndContextIds(final String userId, final String contextId)
{
if (userId == null || contextId == null)
{
throw new IllegalArgumentException("Null Argument");
}
HibernateCallback<SyllabusItem> hcb = session -> {
Query q = session.getNamedQuery(QUERY_BY_USERID_AND_CONTEXTID);
q.setParameter(USER_ID, userId, StringType.INSTANCE);
q.setParameter(CONTEXT_ID, contextId, StringType.INSTANCE);
return (SyllabusItem) q.uniqueResult();
};
return getHibernateTemplate().execute(hcb);
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:24,代码来源:SyllabusManagerImpl.java
示例10: getItemGradingData
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
public ItemGradingData getItemGradingData(final Long assessmentGradingId, final Long publishedItemId) {
log.debug("****assessmentGradingId={}", assessmentGradingId);
log.debug("****publishedItemId={}", publishedItemId);
final HibernateCallback<List<ItemGradingData>> hcb = session -> {
Query q = session.createQuery(
"from ItemGradingData i where i.assessmentGradingId = :gradingid and i.publishedItemId = :itemid");
q.setLong("gradingid", assessmentGradingId);
q.setLong("itemid", publishedItemId);
return q.list();
};
List<ItemGradingData> itemGradings = getHibernateTemplate().execute(hcb);
if (itemGradings.isEmpty()) {
return null;
}
return itemGradings.get(0);
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:19,代码来源:AssessmentGradingFacadeQueries.java
示例11: getLastAssessmentGradingByAgentId
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
public AssessmentGradingData getLastAssessmentGradingByAgentId(final Long publishedAssessmentId, final String agentIdString) {
AssessmentGradingData ag = null;
final HibernateCallback<List<AssessmentGradingData>> hcb = session -> {
Query q = session.createQuery(
"from AssessmentGradingData a where a.publishedAssessmentId = :id and a.agentId = :agent order by a.submittedDate desc");
q.setLong("id", publishedAssessmentId);
q.setString("agent", agentIdString);
return q.list();
};
List<AssessmentGradingData> assessmentGradings = getHibernateTemplate().execute(hcb);
if (!assessmentGradings.isEmpty()) {
ag = assessmentGradings.get(0);
ag.setItemGradingSet(getItemGradingSet(ag.getAssessmentGradingId()));
}
return ag;
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:19,代码来源:AssessmentGradingFacadeQueries.java
示例12: getPoolIdsByItem
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* Return a list of questionPoolId (java.lang.Long)
*
* @param itemId DOCUMENTATION PENDING
* @param poolId DOCUMENTATION PENDING
*/
public List getPoolIdsByItem(final String itemId) {
List idList = new ArrayList();
final HibernateCallback<List> hcb = session -> {
Query q = session.createQuery("select qpi from QuestionPoolItemData as qpi where qpi.itemId = :id");
q.setString("id", itemId);
return q.list();
};
List qpiList = getHibernateTemplate().execute(hcb);
try {
Iterator iter = qpiList.iterator();
while (iter.hasNext()) {
QuestionPoolItemData qpa = (QuestionPoolItemData) iter.next();
idList.add(qpa.getQuestionPoolId()); // return a list of poolId (java.lang.Long)
}
return idList;
}
catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:31,代码来源:QuestionPoolFacadeQueries.java
示例13: findMessageCountByForumId
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
public List<Object[]> findMessageCountByForumId(final Long forumId) {
if (forumId == null) {
log.error("findMessageCountByForumId failed with forumId: " + forumId);
throw new IllegalArgumentException("Null Argument");
}
log.debug("findMessageCountByForumId executing with forumId: " + forumId);
HibernateCallback<List<Object[]>> hcb = session -> {
Query q = session.getNamedQuery("findMessageCountByForumId");
q.setLong("forumId", forumId);
return q.list();
};
return getHibernateTemplate().execute(hcb);
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:MessageForumsMessageManagerImpl.java
示例14: findBySql
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* sql查詢多筆資料
*
* @param sqlString
* @param paramNames
* @param values
* @param columnAliases
* @param types
* @param top
*/
protected <E> List<E> findBySql(final String sqlString, final String[] paramNames, final Object[] values,
final String[] columnAliases, final Object[] types, final Integer top) {
List<E> result = new LinkedList<E>();
try {
result = (List<E>) getHibernateTemplate().executeWithNativeSession(new HibernateCallback<List<E>>() {
@SuppressWarnings("unchecked")
public List<E> doInHibernate(Session session) throws HibernateException {
SQLQuery query = session.createSQLQuery(sqlString);
cacheQuery(query);
processQueryParamters(query, paramNames, values);
processSQLQueryScalar(query, columnAliases, types);
if (top != null) {
query.setMaxResults(top);
}
return query.list();
}
});
} catch (Exception ex) {
throw new CommonDaoException(ex);
}
return result;
}
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:33,代码来源:CommonDaoSupporter.java
示例15: getPublishedItemSet
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
public Set<PublishedItemData> getPublishedItemSet(final Long publishedAssessmentId, final Long sectionId) {
final HibernateCallback<List<PublishedItemData>> hcb = session -> session
.createQuery("select i from PublishedItemData i, PublishedSectionData s, PublishedAssessmentData p " +
"where p.publishedAssessmentId = :id and i.section.id = :section and p = s.assessment and i.section = s")
.setLong("id", publishedAssessmentId)
.setLong("section", sectionId)
.list();
List<PublishedItemData> assessmentGradings = getHibernateTemplate().execute(hcb);
Set<PublishedItemData> itemSet = new HashSet<>();
for (PublishedItemData publishedItemData : assessmentGradings) {
log.debug("itemId = {}", publishedItemData.getItemId());
itemSet.add(publishedItemData);
}
return itemSet;
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:18,代码来源:PublishedAssessmentFacadeQueries.java
示例16: findMessagesByTopicId
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
public List findMessagesByTopicId(final Long topicId) {
if (topicId == null) {
log.error("findMessagesByTopicId failed with topicId: null");
throw new IllegalArgumentException("Null Argument");
}
log.debug("findMessagesByTopicId executing with topicId: " + topicId);
HibernateCallback<List> hcb = session -> {
Query q = session.getNamedQuery(QUERY_BY_TOPIC_ID);
q.setParameter("topicId", topicId, LongType.INSTANCE);
return q.list();
};
return getHibernateTemplate().execute(hcb);
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:MessageForumsMessageManagerImpl.java
示例17: revertAll
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
@Transactional
public int revertAll(final String locale) {
HibernateCallback<Integer> callback = session -> {
Query query = session.createQuery("update MessageBundleProperty set value = null where locale = :locale");
query.setString("locale", locale);
return query.executeUpdate();
};
try {
return getHibernateTemplate().execute(callback);
} catch (Exception e) {
log.warn("Cound not revert all MessageBundleProperty's " + e.getMessage(), e);
}
return 0;
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:MessageBundleServiceImpl.java
示例18: getSections
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
/**
* @inheritDoc
*/
public List getSections(final String siteContext) {
if(log.isDebugEnabled()) log.debug("Getting sections for context " + siteContext);
HibernateCallback<List> hc = session -> {
// Get the sections
Query secQuery = session.getNamedQuery("findSectionsBySiteContext");
secQuery.setParameter("context", siteContext);
List list = secQuery.list();
// Get the teams
Query teamQuery = session.getNamedQuery("findTeamsBySiteContext");
teamQuery.setParameter("context", siteContext);
// Add the teams after the sections
list.addAll(teamQuery.list());
return list;
};
return getHibernateTemplate().execute(hc);
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:22,代码来源:SectionAwarenessHibernateImpl.java
示例19: getAssignmentScoreString
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
@Override
public String getAssignmentScoreString(final String gradebookUid, final String assignmentName, final String studentUid)
throws GradebookNotFoundException, AssessmentNotFoundException {
if (gradebookUid == null || assignmentName == null || studentUid == null) {
throw new IllegalArgumentException("null parameter passed to getAssignment. Values are gradebookUid:"
+ gradebookUid + " assignmentName:" + assignmentName + " studentUid:" + studentUid);
}
final GradebookAssignment assignment = (GradebookAssignment)getHibernateTemplate().execute(new HibernateCallback() {
@Override
public Object doInHibernate(final Session session) throws HibernateException {
return getAssignmentWithoutStats(gradebookUid, assignmentName);
}
});
if (assignment == null) {
throw new AssessmentNotFoundException("There is no assignment with name " + assignmentName + " in gradebook " + gradebookUid);
}
return getAssignmentScoreString(gradebookUid, assignment.getId(), studentUid);
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:23,代码来源:GradebookServiceHibernateImpl.java
示例20: isExplicitlyEnteredCourseGradeRecords
import org.springframework.orm.hibernate4.HibernateCallback; //导入依赖的package包/类
public boolean isExplicitlyEnteredCourseGradeRecords(final Long gradebookId) {
final List<String> studentUids = new ArrayList<>(getAllStudentUids(getGradebookUid(gradebookId)));
if (studentUids.isEmpty()) {
return false;
}
HibernateCallback<Boolean> hc = session -> {
Long result = (Long) session.createCriteria(CourseGradeRecord.class)
.add(Restrictions.isNotNull("enteredGrade"))
.add(Restrictions.eq("gradableObject.gradebook.id", gradebookId))
.add(HibernateCriterionUtils.CriterionInRestrictionSplitter("studentId", studentUids))
.setProjection(Projections.rowCount())
.uniqueResult();
log.debug("total number of explicitly entered course grade records = {}", result);
return result > 0L;
};
return getHibernateTemplate().execute(hc);
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:21,代码来源:BaseHibernateManager.java
注:本文中的org.springframework.orm.hibernate4.HibernateCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论