本文整理汇总了Java中org.springframework.orm.hibernate4.HibernateCallback类的典型用法代码示例。如果您正苦于以下问题:Java HibernateCallback类的具体用法?Java HibernateCallback怎么用?Java HibernateCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HibernateCallback类属于org.springframework.orm.hibernate4包,在下文中一共展示了HibernateCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}