List of usage examples for org.hibernate.criterion Restrictions and
public static LogicalExpression and(Criterion lhs, Criterion rhs)
From source file:com.green.common.service.BaseService.java
License:Open Source License
/** * ?//w ww . jav a 2s. com * @param user ?UserUtils.getUser()?? * @param officeAlias ??dc.createAlias("office", "office"); * @param userAlias ??? * @return ? */ protected static Junction dataScopeFilter(User user, String officeAlias, String userAlias) { // ???? List<String> dataScope = Lists.newArrayList(); Junction junction = Restrictions.disjunction(); // ??? if (!user.isAdmin()) { for (Role r : user.getRoleList()) { if (!dataScope.contains(r.getDataScope()) && StringUtils.isNotBlank(officeAlias)) { boolean isDataScopeAll = false; if (Role.DATA_SCOPE_ALL.equals(r.getDataScope())) { isDataScopeAll = true; } else if (Role.DATA_SCOPE_COMPANY_AND_CHILD.equals(r.getDataScope())) { junction.add(Restrictions.eq(officeAlias + ".id", user.getCompany().getId())); junction.add(Restrictions.like(officeAlias + ".parentIds", user.getCompany().getParentIds() + user.getCompany().getId() + ",%")); } else if (Role.DATA_SCOPE_COMPANY.equals(r.getDataScope())) { junction.add(Restrictions.eq(officeAlias + ".id", user.getCompany().getId())); junction.add(Restrictions.and( Restrictions.eq(officeAlias + ".parent.id", user.getCompany().getId()), Restrictions.eq(officeAlias + ".type", "2"))); // ? } else if (Role.DATA_SCOPE_OFFICE_AND_CHILD.equals(r.getDataScope())) { junction.add(Restrictions.eq(officeAlias + ".id", user.getOffice().getId())); junction.add(Restrictions.like(officeAlias + ".parentIds", user.getOffice().getParentIds() + user.getOffice().getId() + ",%")); } else if (Role.DATA_SCOPE_OFFICE.equals(r.getDataScope())) { junction.add(Restrictions.eq(officeAlias + ".id", user.getOffice().getId())); } else if (Role.DATA_SCOPE_CUSTOM.equals(r.getDataScope())) { junction.add(Restrictions.in(officeAlias + ".id", r.getOfficeIdList())); } //else if (Role.DATA_SCOPE_SELF.equals(r.getDataScope())){ if (!isDataScopeAll) { if (StringUtils.isNotBlank(userAlias)) { junction.add(Restrictions.eq(userAlias + ".id", user.getId())); } else { junction.add(Restrictions.isNull(officeAlias + ".id")); } } else { // ????? junction = Restrictions.disjunction(); break; } dataScope.add(r.getDataScope()); } } } return junction; }
From source file:com.green.modules.cms.service.ArticleService.java
License:Open Source License
@Transactional(readOnly = false) public Page<Article> find(Page<Article> page, Article article, boolean isDataScopeFilter) { // ??6??//from w w w . ja va 2 s . c o m Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByArticle"); if (updateExpiredWeightDate == null || (updateExpiredWeightDate != null && updateExpiredWeightDate.getTime() < new Date().getTime())) { articleDao.updateExpiredWeight(); CacheUtils.put("updateExpiredWeightDateByArticle", DateUtils.addHours(new Date(), 6)); } DetachedCriteria dc = articleDao.createDetachedCriteria(); dc.createAlias("category", "category"); dc.createAlias("category.site", "category.site"); if (article.getCategory() != null && StringUtils.isNotBlank(article.getCategory().getId()) && !Category.isRoot(article.getCategory().getId())) { Category category = categoryDao.get(article.getCategory().getId()); if (category != null) { dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()), Restrictions.like("category.parentIds", "%," + category.getId() + ",%"))); dc.add(Restrictions.eq("category.site.id", category.getSite().getId())); article.setCategory(category); } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } if (StringUtils.isNotEmpty(article.getTitle())) { dc.add(Restrictions.like("title", "%" + article.getTitle() + "%")); } if (StringUtils.isNotEmpty(article.getPosid())) { dc.add(Restrictions.like("posid", "%," + article.getPosid() + ",%")); } if (StringUtils.isNotEmpty(article.getImage()) && Article.YES.equals(article.getImage())) { dc.add(Restrictions.and(Restrictions.isNotNull("image"), Restrictions.ne("image", ""))); } if (article.getCreateBy() != null && StringUtils.isNotBlank(article.getCreateBy().getId())) { dc.add(Restrictions.eq("createBy.id", article.getCreateBy().getId())); } if (isDataScopeFilter) { dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy"); dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy")); } dc.add(Restrictions.eq(Article.FIELD_DEL_FLAG, article.getDelFlag())); if (StringUtils.isBlank(page.getOrderBy())) { dc.addOrder(Order.desc("weight")); dc.addOrder(Order.desc("updateDate")); } return articleDao.find(page, dc); }
From source file:com.hongqiang.shop.modules.cms.service.ArticleService.java
License:Open Source License
public Page<Article> find(Page<Article> page, Article article, boolean isDataScopeFilter) { // ??6??//from www. j a va 2 s . c o m Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByArticle"); if (updateExpiredWeightDate == null || (updateExpiredWeightDate != null && updateExpiredWeightDate.getTime() < new Date().getTime())) { articleDao.updateExpiredWeight(); CacheUtils.put("updateExpiredWeightDateByArticle", DateUtils.addHours(new Date(), 6)); } DetachedCriteria dc = articleDao.createDetachedCriteria(); dc.createAlias("category", "category"); dc.createAlias("category.site", "category.site"); if (article.getCategory() != null && article.getCategory().getId() != null && !Category.isRoot(article.getCategory().getId())) { Category category = categoryDao.findOne(article.getCategory().getId()); if (category != null) { dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()), Restrictions.like("category.parentIds", "%," + category.getId() + ",%"))); dc.add(Restrictions.eq("category.site.id", category.getSite().getId())); article.setCategory(category); } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } if (StringUtils.isNotEmpty(article.getTitle())) { dc.add(Restrictions.like("title", "%" + article.getTitle() + "%")); } if (StringUtils.isNotEmpty(article.getPosid())) { dc.add(Restrictions.like("posid", "%," + article.getPosid() + ",%")); } if (StringUtils.isNotEmpty(article.getImage()) && Article.YES.equals(article.getImage())) { dc.add(Restrictions.and(Restrictions.isNotNull("image"), Restrictions.ne("image", ""))); } if (article.getCreateBy() != null && article.getCreateBy().getId() > 0) { dc.add(Restrictions.eq("createBy.id", article.getCreateBy().getId())); } if (isDataScopeFilter) { dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy"); dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy")); } dc.add(Restrictions.eq(Article.DEL_FLAG, article.getDelFlag())); if (StringUtils.isBlank(page.getOrderBy())) { dc.addOrder(Order.desc("weight")); dc.addOrder(Order.desc("updateDate")); } return articleDao.find(page, dc); }
From source file:com.hp.j2sh.project.action.AuthenticateLogin.java
@Override public String execute() throws Exception { Session session = MyHibernateUtil.getSession(); Criteria criteria = session.createCriteria(AllUsers.class); Criterion usernameCriterion = Restrictions.eq("username", username); Criterion passwordCriterion = Restrictions.eq("password", password); criteria.add(Restrictions.and(usernameCriterion, passwordCriterion)); AllUsers user = (AllUsers) criteria.uniqueResult(); if (user != null) { System.out.println("user_id : " + user.getUserId()); sessionMap.put("user_id", user.getUserId()); System.out.println("user_id : " + (Integer) sessionMap.get("user_id")); Query query = session.createQuery("FROM CommunityUsers c WHERE c.userId = ?"); query.setParameter(0, user.getUserId()); System.out.println("query :: " + query.getQueryString()); List<CommunityUsers> tempList = query.list(); List<AllCommunities> listUser = new ArrayList<AllCommunities>(); for (CommunityUsers communityUsers : tempList) { Criteria criteria2 = session.createCriteria(AllCommunities.class); criteria2.add(Restrictions.eq("communityId", communityUsers.getCommunityId())); AllCommunities allCommunities = (AllCommunities) criteria2.uniqueResult(); listUser.add(allCommunities); }//from w ww .ja v a 2 s . co m sessionMap.put("communityListUser", listUser); List<AllCommunities> listAll = new ArrayList<AllCommunities>(); List<Integer> userIds = new ArrayList<Integer>(); for (AllCommunities allCommunities : listUser) { userIds.add(allCommunities.getCommunityId()); } System.out.println("userIDs :: " + userIds); Criteria criteria1 = session.createCriteria(AllCommunities.class); ArrayList<AllCommunities> tempListAll = (ArrayList<AllCommunities>) criteria1.list(); for (AllCommunities ac : tempListAll) { boolean found = false; for (Integer i : userIds) { if (ac.getCommunityId().equals(i)) { found = true; break; } } if (!found) { listAll.add(ac); } } sessionMap.put("communityListAll", listAll); return SUCCESS; } else { sessionMap.put("loginErrorMessage", "Invalid username and/or password!"); return INPUT; } }
From source file:com.hypersocket.permissions.PermissionRepositoryImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)//w w w . j ava 2s . com public List<Permission> getAllPermissions(final Set<Long> permissions, final boolean includeSystem) { return allEntities(Permission.class, new DetachedCriteriaConfiguration() { @Override public void configure(DetachedCriteria criteria) { if (!includeSystem) { criteria.add( Restrictions.and(Restrictions.eq("system", false), Restrictions.in("id", permissions))); } else { criteria.add(Restrictions.in("id", permissions)); } } }, JOIN_ROLES, new HiddenCriteria(false)); }
From source file:com.hypersocket.session.SessionRepositoryImpl.java
License:Open Source License
@Override public Long getSessionCount(final Date startDate, final Date endDate, final boolean distinctUsers) { Criteria criteria = createCriteria(Session.class); criteria.add(Restrictions.or(/*from w w w . ja v a 2 s.c o m*/ Restrictions.and(Restrictions.ge("created", startDate), Restrictions.lt("created", endDate)), Restrictions.and(Restrictions.lt("created", startDate), Restrictions .or(Restrictions.ge("signedOut", startDate), Restrictions.isNull("signedOut"))))); criteria.add(Restrictions.eq("system", false)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); if (distinctUsers) { criteria.setProjection(Projections.countDistinct("principal")); } else { criteria.setProjection(Projections.rowCount()); } return (long) criteria.uniqueResult(); }
From source file:com.ibm.asset.trails.dao.jpa.VSoftwareLparDAOJpa.java
@Override public Long total(Account account, ReconSetting reconSetting) { // TODO Auto-generated method stub Criteria criteria = getHibernateSessionCriteria(); criteria.createAlias("hardwareLpar", "hl") .createAlias("hl.hardwareLparEff", "hle", CriteriaSpecification.LEFT_JOIN) .createAlias("hl.hardware", "h").createAlias("h.machineType", "mt") .createAlias("installedSoftwares", "is") .createAlias("is.scheduleF", "sf", CriteriaSpecification.LEFT_JOIN) .createAlias("sf.scope", "scope", CriteriaSpecification.LEFT_JOIN) .createAlias("is.softwareLpar", "sl").createAlias("is.alert", "aus") .createAlias("aus.reconcile", "r", CriteriaSpecification.LEFT_JOIN) .createAlias("r.usedLicenses", "ul", CriteriaSpecification.LEFT_JOIN) .createAlias("ul.license", "license", CriteriaSpecification.LEFT_JOIN) .createAlias("r.reconcileType", "rt", CriteriaSpecification.LEFT_JOIN) .createAlias("is.software", "sw").add(Restrictions.eq("account", account)); if (reconSetting.getReconcileType() != null) { criteria.add(Restrictions.eq("rt.id", reconSetting.getReconcileType())); }/*ww w . j a v a 2s . co m*/ if (StringUtils.isNotBlank(reconSetting.getAlertStatus())) { boolean open = false; if (reconSetting.getAlertStatus().equals("OPEN")) { open = true; criteria.add(Restrictions.eq("aus.open", open)); } else { criteria.add(Restrictions.and(Restrictions.eq("aus.open", false), Restrictions.eqProperty("is.id", "r.installedSoftware.id"))); } } else { criteria.add(Restrictions.or(Restrictions.eq("aus.open", true), Restrictions.and(Restrictions.eq("aus.open", false), Restrictions.eqProperty("is.id", "r.installedSoftware.id")))); } if (null != reconSetting.getAlertFrom() && reconSetting.getAlertFrom().intValue() >= 0) { criteria.add(Restrictions.ge("aus.alertAge", reconSetting.getAlertFrom())); } if (null != reconSetting.getAlertTo() && reconSetting.getAlertTo().intValue() >= 0) { criteria.add(Restrictions.le("aus.alertAge", reconSetting.getAlertTo())); } if (StringUtils.isNotBlank(reconSetting.getAssigned())) { if (reconSetting.getAssigned().equals("Assigned")) { criteria.add(Restrictions.ne("aus.remoteUser", "STAGING")); } if (reconSetting.getAssigned().equals("Unassigned")) { criteria.add(Restrictions.eq("aus.remoteUser", "STAGING")); } } if (StringUtils.isNotBlank(reconSetting.getAssignee())) { criteria.add(Restrictions.eq("aus.remoteUser", reconSetting.getAssignee()).ignoreCase()); } if (StringUtils.isNotBlank(reconSetting.getOwner())) { if (reconSetting.getOwner().equalsIgnoreCase("IBM")) { criteria.add(Restrictions.eq("h.owner", reconSetting.getOwner()).ignoreCase()); } else if (reconSetting.getOwner().equalsIgnoreCase("Customer")) { ArrayList<String> lalOwner = new ArrayList<String>(); lalOwner.add("CUST"); lalOwner.add("CUSTO"); criteria.add(Restrictions.in("h.owner", lalOwner)); } } // I'm not sure why the heck we aren't just getting a list of strings? if (reconSetting.getCountries().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getCountries().length; i++) { if (StringUtils.isNotBlank(reconSetting.getCountries()[i])) { list.add(reconSetting.getCountries()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("h.country", list)); } } if (reconSetting.getNames().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getNames().length; i++) { if (StringUtils.isNotBlank(reconSetting.getNames()[i])) { list.add(reconSetting.getNames()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("hl.name", list)); } } if (reconSetting.getSwcmIDs().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getSwcmIDs().length; i++) { if (StringUtils.isNotBlank(reconSetting.getSwcmIDs()[i])) { list.add(reconSetting.getSwcmIDs()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("license.extSrcId", list)); } } if (reconSetting.getSerialNumbers().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getSerialNumbers().length; i++) { if (StringUtils.isNotBlank(reconSetting.getSerialNumbers()[i])) { list.add(reconSetting.getSerialNumbers()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("h.serial", list)); } } if (reconSetting.getProductInfoNames().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getProductInfoNames().length; i++) { if (StringUtils.isNotBlank(reconSetting.getProductInfoNames()[i])) { list.add(reconSetting.getProductInfoNames()[i]); } } if (list.size() > 0) { criteria.add(Restrictions.in("sw.softwareName", list)); } } if (StringUtils.isNotBlank(reconSetting.getScope())) { if ("Not specified".equalsIgnoreCase(reconSetting.getScope())) { criteria.add(Restrictions.isNull("scope.description")); } else { criteria.add(Restrictions.eq("scope.description", reconSetting.getScope())); } } if (StringUtils.isNotBlank(reconSetting.getFinanResp())) { if ("Not Specified".trim().equalsIgnoreCase(reconSetting.getFinanResp())) { criteria.add(Restrictions.isNull("sf.SWFinanceResp")); } else { criteria.add(Restrictions.eq("sf.SWFinanceResp", reconSetting.getFinanResp())); } } criteria.setProjection(Projections.projectionList().add(Projections.rowCount())); Long total = (Long) criteria.uniqueResult(); return total; }
From source file:com.ibm.asset.trails.dao.jpa.VSoftwareLparDAOJpa.java
public void paginatedList(DisplayTagList data, Account account, ReconSetting reconSetting, int startIndex, int objectsPerPage, String sort, String dir) { Criteria criteria = getHibernateSessionCriteria(); criteria.createAlias("hardwareLpar", "hl") .createAlias("hl.hardwareLparEff", "hle", CriteriaSpecification.LEFT_JOIN) .createAlias("hl.hardware", "h").createAlias("h.machineType", "mt") .createAlias("installedSoftwares", "is") .createAlias("is.scheduleF", "sf", CriteriaSpecification.LEFT_JOIN) .createAlias("sf.scope", "scope", CriteriaSpecification.LEFT_JOIN) .createAlias("is.softwareLpar", "sl").createAlias("is.alert", "aus") .createAlias("aus.reconcile", "r", CriteriaSpecification.LEFT_JOIN) .createAlias("r.usedLicenses", "ul", CriteriaSpecification.LEFT_JOIN) .createAlias("ul.license", "license", CriteriaSpecification.LEFT_JOIN) .createAlias("r.reconcileType", "rt", CriteriaSpecification.LEFT_JOIN) .createAlias("is.software", "sw") .createAlias("sw.manufacturer", "mf", CriteriaSpecification.LEFT_JOIN) .add(Restrictions.eq("account", account)); if (reconSetting.getReconcileType() != null) { criteria.add(Restrictions.eq("rt.id", reconSetting.getReconcileType())); }/*from w ww . j a va 2 s .c om*/ if (StringUtils.isNotBlank(reconSetting.getAlertStatus())) { boolean open = false; if (reconSetting.getAlertStatus().equals("OPEN")) { open = true; criteria.add(Restrictions.eq("aus.open", open)); } else { criteria.add(Restrictions.and(Restrictions.eq("aus.open", false), Restrictions.eqProperty("is.id", "r.installedSoftware.id"))); } } else { criteria.add(Restrictions.or(Restrictions.eq("aus.open", true), Restrictions.and(Restrictions.eq("aus.open", false), Restrictions.eqProperty("is.id", "r.installedSoftware.id")))); } if (null != reconSetting.getAlertFrom() && reconSetting.getAlertFrom().intValue() >= 0) { criteria.add(Restrictions.ge("aus.alertAge", reconSetting.getAlertFrom())); } if (null != reconSetting.getAlertTo() && reconSetting.getAlertTo().intValue() >= 0) { criteria.add(Restrictions.le("aus.alertAge", reconSetting.getAlertTo())); } if (StringUtils.isNotBlank(reconSetting.getAssigned())) { if (reconSetting.getAssigned().equals("Assigned")) { criteria.add(Restrictions.ne("aus.remoteUser", "STAGING")); } if (reconSetting.getAssigned().equals("Unassigned")) { criteria.add(Restrictions.eq("aus.remoteUser", "STAGING")); } } if (StringUtils.isNotBlank(reconSetting.getAssignee())) { criteria.add(Restrictions.eq("aus.remoteUser", reconSetting.getAssignee()).ignoreCase()); } if (StringUtils.isNotBlank(reconSetting.getOwner())) { if (reconSetting.getOwner().equalsIgnoreCase("IBM")) { criteria.add(Restrictions.eq("h.owner", reconSetting.getOwner()).ignoreCase()); } else if (reconSetting.getOwner().equalsIgnoreCase("Customer")) { ArrayList<String> lalOwner = new ArrayList<String>(); lalOwner.add("CUST"); lalOwner.add("CUSTO"); criteria.add(Restrictions.in("h.owner", lalOwner)); } } // I'm not sure why the heck we aren't just getting a list of strings? if (reconSetting.getCountries().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getCountries().length; i++) { if (StringUtils.isNotBlank(reconSetting.getCountries()[i])) { list.add(reconSetting.getCountries()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("h.country", list)); } } if (reconSetting.getNames().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getNames().length; i++) { if (StringUtils.isNotBlank(reconSetting.getNames()[i])) { list.add(reconSetting.getNames()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("hl.name", list)); } } if (reconSetting.getSwcmIDs().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getSwcmIDs().length; i++) { if (StringUtils.isNotBlank(reconSetting.getSwcmIDs()[i])) { list.add(reconSetting.getSwcmIDs()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("license.extSrcId", list)); } } if (reconSetting.getSerialNumbers().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getSerialNumbers().length; i++) { if (StringUtils.isNotBlank(reconSetting.getSerialNumbers()[i])) { list.add(reconSetting.getSerialNumbers()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("h.serial", list)); } } if (reconSetting.getProductInfoNames().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getProductInfoNames().length; i++) { if (StringUtils.isNotBlank(reconSetting.getProductInfoNames()[i])) { list.add(reconSetting.getProductInfoNames()[i]); } } if (list.size() > 0) { criteria.add(Restrictions.in("sw.softwareName", list)); } } if (StringUtils.isNotBlank(reconSetting.getScope())) { if ("Not specified".equalsIgnoreCase(reconSetting.getScope())) { criteria.add(Restrictions.isNull("scope.description")); } else { criteria.add(Restrictions.eq("scope.description", reconSetting.getScope())); } } if (StringUtils.isNotBlank(reconSetting.getFinanResp())) { if ("Not Specified".trim().equalsIgnoreCase(reconSetting.getFinanResp())) { criteria.add(Restrictions.isNull("sf.SWFinanceResp")); } else { criteria.add(Restrictions.eq("sf.SWFinanceResp", reconSetting.getFinanResp())); } } criteria.setProjection(Projections.projectionList().add(Projections.property("aus.id").as("alertId")) .add(Projections.property("r.id").as("reconcileId")) .add(Projections.property("aus.alertAge").as("alertAgeI")) .add(Projections.property("is.id").as("installedSoftwareId")) .add(Projections.property("hl.name").as("hostname")) .add(Projections.property("sl.name").as("sl_hostname")) .add(Projections.property("hl.spla").as("spla")) .add(Projections.property("hl.sysplex").as("sysplex")) .add(Projections.property("hl.internetIccFlag").as("internetIccFlag")) .add(Projections.property("h.serial").as("serial")) .add(Projections.property("h.country").as("country")) .add(Projections.property("h.owner").as("owner")) .add(Projections.property("h.mastProcessorType").as("mastProcessorType")) .add(Projections.property("h.processorManufacturer").as("processorManufacturer")) .add(Projections.property("h.mastProcessorModel").as("mastProcessorModel")) .add(Projections.property("h.nbrCoresPerChip").as("nbrCoresPerChip")) .add(Projections.property("h.nbrOfChipsMax").as("nbrOfChipsMax")) .add(Projections.property("h.cpuLsprMips").as("cpuLsprMips")) .add(Projections.property("h.cpuIfl").as("cpuIFL")) .add(Projections.property("hl.partLsprMips").as("partLsprMips")) .add(Projections.property("h.cpuGartnerMips").as("cpuGartnerMips")) .add(Projections.property("hl.partGartnerMips").as("partGartnerMips")) .add(Projections.property("hl.effectiveThreads").as("effectiveThreads")) .add(Projections.property("hl.vcpu").as("vcpu")).add(Projections.property("h.cpuMsu").as("cpuMsu")) .add(Projections.property("hl.partMsu").as("partMsu")) .add(Projections.property("hl.serverType").as("lparServerType")) .add(Projections.property("h.shared").as("shared")) .add(Projections.property("h.multi_tenant").as("multi_tenant")) .add(Projections.property("mt.type").as("assetType")) .add(Projections.property("mt.name").as("assetName")) .add(Projections.property("h.hardwareStatus").as("hardwareStatus")) .add(Projections.property("hl.lparStatus").as("lparStatus")) .add(Projections.property("processorCount").as("processorCount")) .add(Projections.property("sw.softwareName").as("productInfoName")) .add(Projections.property("sw.softwareId").as("productInfoId")) .add(Projections.property("sw.pid").as("pid")) .add(Projections.property("mf.manufacturerName").as("manufacturerName")) .add(Projections.property("rt.name").as("reconcileTypeName")) .add(Projections.property("rt.id").as("reconcileTypeId")) .add(Projections.property("aus.remoteUser").as("assignee")) .add(Projections.property("h.processorCount").as("hardwareProcessorCount")) .add(Projections.property("hle.processorCount").as("hwLparEffProcessorCount")) .add(Projections.property("hl.osType").as("osType")) .add(Projections.property("hle.status").as("hwLparEffProcessorStatus")) .add(Projections.property("h.chips").as("chips"))); criteria.setResultTransformer(new AliasToBeanResultTransformer(ReconWorkspace.class)); criteria.addOrder(Order.desc("aus.open")); if (dir.equalsIgnoreCase("ASC")) { criteria.addOrder(Order.asc(sort)); } else { criteria.addOrder(Order.desc(sort)); } ArrayList<ReconWorkspace> list = new ArrayList<ReconWorkspace>(); ScrollableResults itemCursor = criteria.scroll(); itemCursor.beforeFirst(); if (itemCursor.next()) { itemCursor.scroll(startIndex); int i = 0; while (objectsPerPage > i++) { ReconWorkspace rw = (ReconWorkspace) itemCursor.get(0); if (null != rw.getHwLparEffProcessorStatus() && rw.getHwLparEffProcessorStatus().equalsIgnoreCase("INACTIVE")) { rw.setHwLparEffProcessorCount(0); } list.add(rw); if (!itemCursor.next()) break; } data.setList(list); itemCursor.last(); data.setFullListSize(itemCursor.getRowNumber() + 1); itemCursor.close(); addSchedulef2List(account, data.getList()); } else { data.setList(null); data.setFullListSize(0); itemCursor.close(); } }
From source file:com.inet.mail.business.sr.MailHeaderSLBean.java
License:Open Source License
/** * Count the list of mail header from the given criteria. * /*from w ww . j a v a 2 s .c om*/ * @param criteria the given mail header. * @return the number of header information. */ @TransactionAttribute(TransactionAttributeType.SUPPORTS) private int count(String criteria) throws EJBException { if (criteria == null) { throw new EJBException("The search criteria is not validate !"); } // create criteria. Criteria query = this.getCriteria(MailHeader.class); // set projection. query.setProjection(Projections.rowCount()); // build the query. query.add(Restrictions.and( Restrictions.or(Property.forName("subject").like(criteria, MatchMode.ANYWHERE).ignoreCase(), Property.forName("sender").like(criteria, MatchMode.ANYWHERE).ignoreCase()), Property.forName("owner").eq(getUserCode()))); // count the result. return count(query); }
From source file:com.inet.mail.business.sr.MailHeaderSLBean.java
License:Open Source License
/** * Create the search criteria from the given search value. * /*w ww . jav a 2 s. c o m*/ * @param criteria the given search criteria. * * @return the search {@link Criteria} instance. * @throws EJBException when error occurs during building query. */ @TransactionAttribute(TransactionAttributeType.SUPPORTS) protected Criteria buildQuery(String criteria) throws EJBException { if (criteria == null) { throw new EJBException("The search criteria is not validate !"); } // create criteria. Criteria query = this.getCriteria(MailHeader.class); // build the query. query.add(Restrictions.and( Restrictions.or(Property.forName("subject").like(criteria, MatchMode.ANYWHERE).ignoreCase(), Property.forName("sender").like(criteria, MatchMode.ANYWHERE).ignoreCase()), Property.forName("owner").eq(getUserCode()))); // sort by received date. query.addOrder(Order.desc("received")); return query; }