本文整理汇总了Java中org.hibernate.Criteria.add方法的典型用法代码示例。如果您正苦于以下问题:Java Criteria.add方法的具体用法?Java Criteria.add怎么用?Java Criteria.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Criteria
的用法示例。
在下文中一共展示了Criteria.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: searchByFilter
import org.hibernate.Criteria; //导入方法依赖的package包/类
private Criteria searchByFilter(Integer tagId, Integer catalog, Short tagType, String keywords) {
Criteria cri = getSession().createCriteria(ViewTagApps.class);
if (tagType != null) {
cri.add(Restrictions.eq("tagType", tagType));
}
if (tagId != null && tagId > 0) {
cri.add(Restrictions.eq("tagId", tagId));
}
if (catalog != null && catalog > 0) {
cri.add(Restrictions.eq("catalog", catalog));
}
if (keywords != null && !keywords.isEmpty()) {
cri.add(Restrictions.or(Restrictions.like("appName", keywords, MatchMode.ANYWHERE),
Restrictions.like("marketName", keywords, MatchMode.ANYWHERE),
Restrictions.like("tagName", keywords, MatchMode.ANYWHERE)));
}
return cri;
}
示例3: handleFindCollidingTrialGroupVisit
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
protected Collection<VisitScheduleItem> handleFindCollidingTrialGroupVisit(Long trialId, Long groupId, Long visitId) throws Exception
{
Criteria visitScheduleItemCriteria = createVisitScheduleItemCriteria(null);
if (trialId != null) {
visitScheduleItemCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
}
if (groupId != null) {
visitScheduleItemCriteria.add(Restrictions.eq("group.id", groupId.longValue()));
} else {
visitScheduleItemCriteria.add(Restrictions.isNull("group.id"));
}
if (visitId != null) {
visitScheduleItemCriteria.add(Restrictions.eq("visit.id", visitId.longValue()));
} else {
visitScheduleItemCriteria.add(Restrictions.isNull("visit.id"));
}
return visitScheduleItemCriteria.list();
}
示例4: get
import org.hibernate.Criteria; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<E> get(E entity) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try
{
session.beginTransaction();
Criteria crit = session.createCriteria(entityClass);
crit.add(Restrictions.idEq(entity));
List <E> resultList = crit.list();
session.getTransaction().commit();
return resultList;
}
catch (HibernateException e)
{
//log.error("Hibernate Exception" + e.getMessage());
session.getTransaction().rollback();
throw new RuntimeException(e);
}
}
示例5: getMenusByRoleId
import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
* @param roleId
* @param onlyMenu 区分是用来生成所有权限code,还是仅展示左侧菜单树
* @return
*/
@SuppressWarnings("unchecked")
@Transactional(readOnly = true, rollbackFor = Exception.class)
public List<MenuDO> getMenusByRoleId(String roleId, Boolean onlyMenu) {
Criteria rmCtr = daoSupport.createCriteria(RoleMenuDO.class);
rmCtr.add(Restrictions.eq("roleId", roleId));
List<RoleMenuDO> roleMenus = rmCtr.list();
Criteria menuCtr = daoSupport.createCriteria(MenuDO.class);
if (onlyMenu) {
menuCtr.add(Restrictions.eq("menuType", "menu"));
}
List<MenuDO> menus = menuCtr.list();
List<MenuDO> result = new ArrayList<MenuDO>();
menus.forEach(menu -> {
roleMenus.forEach(roleMenu -> {
if (menu.getMenuId().equals(roleMenu.getMenuId())) {
result.add(menu);
}
});
}
);
return result;
}
示例6: handleFindByTrialCalendarInterval
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
protected Collection<InventoryBooking> handleFindByTrialCalendarInterval(
Long trialId, String calendar, Timestamp from, Timestamp to,
Boolean isRelevantForTrialAppointments) throws Exception {
Criteria bookingCriteria = createBookingCriteria();
CriteriaUtil.applyClosedIntervalCriterion(bookingCriteria, from, to, null);
if (trialId != null) {
bookingCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
}
if (isRelevantForTrialAppointments != null) {
bookingCriteria.createCriteria("inventory", CriteriaSpecification.INNER_JOIN).createCriteria("category", CriteriaSpecification.INNER_JOIN)
.add(Restrictions.eq("relevantForTrialAppointments", isRelevantForTrialAppointments.booleanValue()));
}
CategoryCriterion.apply(bookingCriteria, new CategoryCriterion(calendar, "calendar", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS));
return bookingCriteria.list();
}
示例7: searchByFilter
import org.hibernate.Criteria; //导入方法依赖的package包/类
private Criteria searchByFilter(EnumMarket enumMarket, Short catalog, Integer subCatalog, String keywords) {
Criteria cri = getSession().createCriteria(MarketApp.class);
if (enumMarket != null) {
cri.add(Restrictions.eq("marketName", enumMarket.getName()));
}
if (catalog != null) {
cri.add(Restrictions.eq("catalog", catalog));
}
if (subCatalog != null) {
cri.add(Restrictions.eq("subCatalog", subCatalog));
}
if (keywords != null && !keywords.isEmpty()) {
cri.add(Restrictions.like("name", keywords, MatchMode.ANYWHERE));
}
return cri;
}
示例8: listForBase
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<App> listForBase(short catalog, Integer subCatalog, int currentPage, int pageSize) {
ProjectionList proList = Projections.projectionList();
proList.add(Projections.property("id"));
proList.add(Projections.property("name"));
proList.add(Projections.property("subCatalog"));
proList.add(Projections.property("auditCatalog"));
Criteria cri = getSession().createCriteria(App.class);
cri.setProjection(proList);
cri.addOrder(Order.asc("auditCatalog"));
cri.addOrder(Order.asc("name"));
cri.add(Restrictions.eq("catalog", catalog));
if (subCatalog != null) {
cri.add(Restrictions.eq("subCatalog", subCatalog));
}
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((Integer) obj[0], (String) obj[1]);
e.setSubCatalog((Integer) obj[2]);
e.setAuditCatalog((Boolean) obj[3]);
apps.add(e);
}
list.clear();
}
return apps;
}
示例9: getTokenForSeries
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public PersistentRememberMeToken getTokenForSeries(String seriesId) {
logger.info("Fetch Token if any for seriesId : {}", seriesId);
try {
Criteria crit = createEntityCriteria();
crit.add(Restrictions.eq("series", seriesId));
PersistentLogin persistentLogin = (PersistentLogin) crit.uniqueResult();
return new PersistentRememberMeToken(persistentLogin.getUsername(), persistentLogin.getSeries(),
persistentLogin.getToken(), persistentLogin.getLast_used());
} catch (Exception e) {
logger.info("Token not found...");
return null;
}
}
示例10: handleFindByProbandInterval
import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
* @inheritDoc
*/
@Override
protected Collection<ProbandStatusEntry> handleFindByProbandInterval(Long probandId, Timestamp from, Timestamp to, Boolean probandActive)
{
Criteria statusEntryCriteria = createStatusEntryCriteria();
CriteriaUtil.applyStopOpenIntervalCriterion(statusEntryCriteria, from, to, null);
if (probandActive != null) {
statusEntryCriteria.createCriteria("type", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("probandActive", probandActive.booleanValue()));
}
if (probandId != null) {
statusEntryCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
}
return statusEntryCriteria.list();
}
示例11: handleFindByStaff
import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
* @throws Exception
* @inheritDoc
*/
@Override
protected Collection<DutyRosterTurn> handleFindByStaff(Long staffId, PSFVO psf) throws Exception
{
Criteria dutyRosterCriteria = createDutyRosterTurnCriteria(null);
SubCriteriaMap criteriaMap = new SubCriteriaMap(DutyRosterTurn.class, dutyRosterCriteria);
if (staffId != null) {
dutyRosterCriteria.add(Restrictions.eq("staff.id", staffId.longValue()));
}
CriteriaUtil.applyPSFVO(criteriaMap, psf);
return dutyRosterCriteria.list();
}
示例12: handleFindByStaffInterval
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
protected Collection<StaffStatusEntry> handleFindByStaffInterval(
Long staffId, Timestamp from, Timestamp to, Boolean staffActive)
throws Exception {
Criteria statusEntryCriteria = createStatusEntryCriteria();
CriteriaUtil.applyStopOpenIntervalCriterion(statusEntryCriteria, from, to, null);
if (staffActive != null) {
statusEntryCriteria.createCriteria("type", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("staffActive", staffActive.booleanValue()));
}
if (staffId != null) {
statusEntryCriteria.add(Restrictions.eq("staff.id", staffId.longValue()));
}
return statusEntryCriteria.list();
}
示例13: searchByFilter
import org.hibernate.Criteria; //导入方法依赖的package包/类
private Criteria searchByFilter(Short pId, String keywords) {
Criteria cri = getSession().createCriteria(MoTag.class);
if (pId != null) {
cri.add(Restrictions.eq("pid", Integer.valueOf(pId)));
}
if (StringUtils.isNotBlank(keywords)) {
cri.add(Restrictions.like("name", keywords, MatchMode.ANYWHERE));
}
return cri;
}
示例14: searchByFilter
import org.hibernate.Criteria; //导入方法依赖的package包/类
private Criteria searchByFilter(String keyword) {
Criteria cri = getSession().createCriteria(User.class);
if (StringUtils.isNotEmpty(keyword)) {
cri.add(Restrictions.like("name", keyword, MatchMode.ANYWHERE));
}
return cri;
}
示例15: search
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<Keyword> search(int page, int rows, String q, String sort, String order) {
Criteria cri = getSession().createCriteria(Keyword.class);
if (q != null && !q.isEmpty()) {
cri.add(Restrictions.like("name", q, MatchMode.ANYWHERE));
}
if (sort != null && !sort.isEmpty()) {
HibernateHelper.addOrder(cri, sort, order);
}
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
List<Keyword> list = HibernateHelper.list(cri);
return list;
}