本文整理汇总了Java中org.hibernate.Criteria类的典型用法代码示例。如果您正苦于以下问题:Java Criteria类的具体用法?Java Criteria怎么用?Java Criteria使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Criteria类属于org.hibernate包,在下文中一共展示了Criteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAppsOfDropMarket
import org.hibernate.Criteria; //导入依赖的package包/类
@Override
public List<App> getAppsOfDropMarket(Session session, String marketName, Integer currentPage, Integer pageSize) {
ProjectionList proList = Projections.projectionList();
proList.add(Projections.property("pkname"));
proList.add(Projections.property("signatureSha1"));
Criteria cri = session.createCriteria(App.class);
cri.setProjection(proList);
cri.setMaxResults(pageSize);
cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
List<Object[]> list = HibernateHelper.list(cri);
List<App> apps = null;
if (list != null) {
apps = new ArrayList<App>(list.size());
for (Object[] obj : list) {
App e = new App();
e.setPkname((String) obj[0]);
e.setSignatureSha1((String) obj[1]);
apps.add(e);
}
list.clear();
}
return apps;
}
示例2: getNewsInfoByConditionAndPage
import org.hibernate.Criteria; //导入依赖的package包/类
/**
* 根据条件查询指定新闻
*/
@Override
public List<?> getNewsInfoByConditionAndPage(NewsInfo condition, int page, int pageSize) {
Session session = SessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(NewsInfo.class);
if (condition != null) {
if (condition.getTopic() != null && condition.getTopic().getId() != null ) {
criteria.add(Restrictions.eq("topic.id", condition.getTopic().getId()));
}
if (condition.getTitle() != null && !"".equals(condition.getTitle())) {
criteria.add(Restrictions.like("title", condition.getTitle(), MatchMode.ANYWHERE));
}
}
criteria.setFirstResult(pageSize * (page - 1));
criteria.setMaxResults(pageSize);
criteria.addOrder(Order.desc("createDate"));
return criteria.list();
}
示例3: handleFindMaxPosition
import org.hibernate.Criteria; //导入依赖的package包/类
@Override
protected Long handleFindMaxPosition(Long trialId, Long groupId) throws Exception {
org.hibernate.Criteria ecrfCriteria = createEcrfCriteria(null);
if (trialId != null) {
ecrfCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
}
if (groupId != null) {
ecrfCriteria.add(Restrictions.eq("group.id", groupId.longValue()));
} else {
ecrfCriteria.add(Restrictions.isNull("group.id"));
}
// if (visitId != null) {
// ecrfCriteria.add(Restrictions.eq("visit.id", visitId.longValue()));
// } else {
// ecrfCriteria.add(Restrictions.isNull("visit.id"));
// }
ecrfCriteria.setProjection(Projections.max("position"));
return (Long) ecrfCriteria.uniqueResult();
}
示例4: pageAdminsByConditions
import org.hibernate.Criteria; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Pagination<AdminDO> pageAdminsByConditions(Integer pageIndex, Integer pageSize, Map<String, Object> params){
//获取记录总数
Criteria criteria = daoSupport.createCriteria(AdminDO.class);
//相当于 select count(uid)
criteria.setProjection(Projections.count("uid"));
//设置查询条件
if (Objects.nonNull(params)) {
criteria.add(Restrictions.allEq(params));
}
criteria.add(Restrictions.eq("editEnable", Boolean.TRUE));
Long total = (Long) criteria.uniqueResult();
//开始查询列表,首先清除count查询所用Projection
criteria.setProjection(null);
criteria.setFirstResult((pageIndex - 1)* pageSize);
criteria.setMaxResults(pageIndex * pageSize);
List<AdminDO> admins = criteria.list();
Pagination<AdminDO> pagination = new Pagination<AdminDO>(Long.valueOf(pageIndex), Long.valueOf(pageSize), total);
pagination.setItems(admins);
return pagination;
}
示例5: listMarketRank
import org.hibernate.Criteria; //导入依赖的package包/类
@Override
public List<Market> listMarketRank() {
ProjectionList proList = Projections.projectionList();
proList.add(Projections.property("marketName"));
proList.add(Projections.property("rank"));
Criteria cri = getSession().createCriteria(Market.class);
cri.setProjection(proList);
List<Object[]> list = HibernateHelper.list(cri);
List<Market> markets = null;
if (list != null && !list.isEmpty()) {
markets = new ArrayList<Market>(list.size());
for (Object[] obj : list) {
Market m = new Market();
m.setMarketName((String) obj[0]);
m.setRank((Integer) obj[1]);
markets.add(m);
}
}
return markets;
}
示例6: countDownloadByUserSince
import org.hibernate.Criteria; //导入依赖的package包/类
public int countDownloadByUserSince (final User user, final Date date)
{
Long result =
getHibernateTemplate ().execute (new HibernateCallback<Long> ()
{
@Override
public Long doInHibernate (Session session)
throws HibernateException, SQLException
{
Criteria criteria = session.createCriteria (
NetworkUsage.class);
criteria.setProjection (Projections.rowCount ());
criteria.add (Restrictions.eq ("isDownload", true));
criteria.add (Restrictions.eq ("user", user));
criteria.add (Restrictions.gt ("date", date));
return (Long) criteria.uniqueResult ();
}
});
return (result != null) ? result.intValue () : 0;
}
示例7: handleFindByStaffSection
import org.hibernate.Criteria; //导入依赖的package包/类
/**
* @inheritDoc
*/
@Override
protected Collection<CourseParticipationStatusEntry> handleFindByStaffSection(Long staffId, Long sectionId, Boolean showCv, Boolean pass, Boolean showCvPreset, PSFVO psf)
throws Exception
{
org.hibernate.Criteria courseParticipationStatusEntryCriteria = createCourseParticipationStatusEntryCriteria();
SubCriteriaMap criteriaMap = new SubCriteriaMap(CourseParticipationStatusEntry.class, courseParticipationStatusEntryCriteria);
if (staffId != null) {
courseParticipationStatusEntryCriteria.add(Restrictions.eq("staff.id", staffId.longValue()));
}
if (showCvPreset != null) {
criteriaMap.createCriteria("course").add(Restrictions.eq("showCvPreset", showCvPreset.booleanValue()));
}
if (sectionId != null) {
courseParticipationStatusEntryCriteria.add(Restrictions.eq("section.id", sectionId.longValue()));
}
if (showCv != null) {
courseParticipationStatusEntryCriteria.add(Restrictions.eq("showCv", showCv.booleanValue()));
}
if (pass != null) {
criteriaMap.createCriteria("status").add(Restrictions.eq("pass", pass.booleanValue()));
}
CriteriaUtil.applyPSFVO(criteriaMap, psf);
return courseParticipationStatusEntryCriteria.list();
}
示例8: searchByFilter
import org.hibernate.Criteria; //导入依赖的package包/类
private Criteria searchByFilter(Short catalog, Integer subCatalog, String keywords, Integer id) {
Criteria cri = getSession().createCriteria(App.class);
if (catalog != null) {
cri.add(Restrictions.eq("catalog", catalog));
}
if (subCatalog != null) {
cri.add(Restrictions.eq("subCatalog", subCatalog));
}
if (id != null && id > 0) {
cri.add(Restrictions.eq("id", id));
}
if (keywords != null && !keywords.isEmpty()) {
cri.add(Restrictions.like("name", keywords, MatchMode.START));
}
return cri;
}
示例9: getQuizByTitle
import org.hibernate.Criteria; //导入依赖的package包/类
@Override
public Quiz getQuizByTitle(String quizTitle) {
Session session = HibernateUtil.getSession();
Criteria criteria;
Quiz test = null;
try {
criteria = session.createCriteria(Quiz.class);
//Adds like restriction to search for a particular username
test = (Quiz)criteria.add(Restrictions.like("quizTitle", quizTitle)).uniqueResult();
}
catch(HibernateException he) {
he.printStackTrace();
}finally {
session.close();
}
return test;
}
示例10: searchForRolling
import org.hibernate.Criteria; //导入依赖的package包/类
@Override
public List<Rollinfo> searchForRolling(Short catalog, Integer subCatalog, int page, int rows, String keywords,
String sort, String order) {
Criteria cri = getSession().createCriteria(Rollinfo.class);
Criteria appCriteria = cri.createCriteria("app", JoinType.LEFT_OUTER_JOIN);
if (catalog != null) {
appCriteria.add(Restrictions.eq("catalog", catalog));
}
if (subCatalog != null) {
appCriteria.add(Restrictions.eq("subCatalog", subCatalog));
}
if (keywords != null && !keywords.isEmpty()) {
appCriteria.add(Restrictions.like("name", keywords, MatchMode.ANYWHERE));
}
if (sort != null && !sort.isEmpty()) {
HibernateHelper.addOrder(appCriteria, sort, order);
}
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
List<Rollinfo> list = HibernateHelper.list(cri);
return list;
}
示例11: handleGetCount
import org.hibernate.Criteria; //导入依赖的package包/类
@Override
protected long handleGetCount(Long trialId, Long groupId, Long visitId, Boolean active) throws Exception {
org.hibernate.Criteria ecrfCriteria = createEcrfCriteria(null);
if (trialId != null) {
ecrfCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
}
if (groupId != null) {
ecrfCriteria.add(Restrictions.or(Restrictions.eq("group.id", groupId.longValue()),
Restrictions.isNull("group.id")));
}
if (visitId != null) {
ecrfCriteria.add(Restrictions.or(Restrictions.eq("visit.id", visitId.longValue()),
Restrictions.isNull("visit.id")));
}
if (active != null) {
ecrfCriteria.add(Restrictions.eq("active", active.booleanValue()));
}
return (Long) ecrfCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
示例12: createCriteria
import org.hibernate.Criteria; //导入依赖的package包/类
/**
* 根据entityClass,生成带排序的Criteria.
*
* @param <T>
* 实体类型
* @param entityClass
* 类型
* @param orderBy
* 排序字段名
* @param isAsc
* 是否正序
* @param criterions
* 条件
* @return Criteria
*/
public <T> Criteria createCriteria(Class<T> entityClass, String orderBy,
boolean isAsc, Criterion... criterions) {
if (StringUtils.hasText(orderBy)) {
Criteria criteria = createCriteria(entityClass, criterions);
if (isAsc) {
criteria.addOrder(Order.asc(orderBy));
} else {
criteria.addOrder(Order.desc(orderBy));
}
return criteria;
} else {
return createCriteria(entityClass, criterions);
}
}
示例13: queryList
import org.hibernate.Criteria; //导入依赖的package包/类
/**
* 分页查询数据
* @param filters Map<String, Object>查询参数和条件数据<br />
* 需要重写queryParam(Criteria criteria)方法
* @return Page
*/
public List<E> queryList(final PageRequest pageRequest)
{
return (List<E>)getHibernateTemplate().execute(new HibernateCallback()
{
public List<E> doInHibernate(Session session) throws HibernateException//, SQLException
{
Criteria criteria = session.createCriteria(getEntityClass());
if (pageRequest.getFilters() instanceof Map)
{
queryParam((Map)pageRequest.getFilters(), criteria);
}
return queryList(criteria, pageRequest);
}
});
}
示例14: getObjectByName
import org.hibernate.Criteria; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public E getObjectByName(String name) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try
{
E entity = null;
session.beginTransaction();
Criteria crit = session.createCriteria(entityClass);
crit.add(Restrictions.eq("name",name));
List<E> resultList = crit.list();
if (resultList.size() > 0) {
entity = (E) crit.list().get(0);
}
session.getTransaction().commit();
return entity;
}
catch (HibernateException e)
{
//log.error("Hibernate Exception" + e.getMessage());
session.getTransaction().rollback();
throw new RuntimeException(e);
}
}
示例15: getColumns
import org.hibernate.Criteria; //导入依赖的package包/类
/**
* REVISAR NIKOLAS
*/
@Override
public String[] getColumns(
String propertyName,
Criteria subcriteria) throws HibernateException {
// return getPropertyMapping( getEntityName( subcriteria, propertyName ) )
// .toColumns(
// getSQLAlias( subcriteria, propertyName ),
// getPropertyName( propertyName )
// );
String alias = getSQLAlias( subcriteria, propertyName );
String property = getPropertyName( propertyName );
String _root = AbstractEntityPersister.generateTableAlias(
alias,
0
);
return new String[]{_root+"."+property};
}