List of usage examples for org.hibernate.criterion Projections projectionList
public static ProjectionList projectionList()
From source file:com.court.controller.OldLoansFxmlController.java
private Set<Member> getAvailableGuarantors() { String mbrId = mbr_search_txt.getText().split("-")[0].trim(); //GET ALL MEMBERS EXPECT GRANTOR====== Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c2 = session.createCriteria(Member.class); c2.add(Restrictions.ne("memberId", mbrId)); c2.add(Restrictions.eq("status", true)); c2.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId") .add(Projections.property("fullName"), "fullName")); c2.setResultTransformer(Transformers.aliasToBean(Member.class)); List<Member> list = c2.list(); session.close();/*from w ww .j a v a 2 s .com*/ return new HashSet<>(list); }
From source file:com.court.controller.OldLoansFxmlController.java
public String fillMemberLoanCodeTxt() { DocSeqHandler seqHandler = new DocSeqHandler(); Session session = HibernateUtil.getSessionFactory().openSession(); Criteria c = session.createCriteria(MemberLoan.class); c.setProjection(Projections.projectionList().add(Projections.property("id"), "id") .add(Projections.property("memberLoanCode"), "memberLoanCode")); c.addOrder(Order.desc("id")); c.setMaxResults(1);//from www . j a va 2s.co m c.setResultTransformer(Transformers.aliasToBean(MemberLoan.class)); MemberLoan ln = (MemberLoan) c.uniqueResult(); session.close(); if (ln != null) { seqHandler.reqTable(TABLE_NAME, Integer.parseInt(ln.getMemberLoanCode().replaceAll("\\D+", "")) + 1); return seqHandler.getSeq_code(); } else { seqHandler.reqTable(TABLE_NAME, 0); return seqHandler.getSeq_code(); } }
From source file:com.court.controller.ReportFormFxmlController.java
private List<Branch> getBranches(boolean withAll) { List<Branch> bList = new ArrayList<>(); if (withAll) { bList.add(new Branch(null, "All")); }/*from w w w . j a va 2s . co m*/ Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(Branch.class); c.add(Restrictions.eq("status", true)); c.setProjection(Projections.projectionList().add(Projections.property("branchCode"), "branchCode") .add(Projections.property("branchName"), "branchName")); c.setResultTransformer(Transformers.aliasToBean(Branch.class)); List<Branch> list = c.list(); bList.addAll(list); s.close(); return bList; }
From source file:com.court.controller.ReportFormFxmlController.java
private List<Branch> getPaymentOffice() { List<Branch> bList = new ArrayList<>(); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(Branch.class); c.add(Restrictions.eq("status", true)); c.add(Restrictions.eq("parentId", 0)); c.setProjection(Projections.projectionList().add(Projections.property("branchCode"), "branchCode") .add(Projections.property("branchName"), "branchName")); c.setResultTransformer(Transformers.aliasToBean(Branch.class)); List<Branch> list = c.list(); bList.addAll(list);//from w w w.j ava 2s .co m s.close(); return bList; }
From source file:com.court.controller.ReportFormFxmlController.java
private List<Member> getMembers(boolean withAll) { Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(Member.class); c.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId") .add(Projections.property("fullName"), "fullName")); c.setResultTransformer(Transformers.aliasToBean(Member.class)); List<Member> list = c.list(); if (withAll) { list.add(new Member("All")); }/*ww w. java 2 s . co m*/ s.close(); return list; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationDao.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Override//w ww. jav a 2 s . c om public List<Integer> getTopXVulnerableAppsFromList(int numApps, List<Integer> teamIdList, List<Integer> applicationIdList, List<Integer> tagIdList, List<Integer> vulnTagIdList) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Application.class); criteria.createAlias("vulnerabilities", "vulnerability"); criteria.add(Restrictions.eq("active", true)); criteria.add(Restrictions.eq("vulnerability.active", true)); criteria.add(Restrictions.eq("vulnerability.hidden", false)); criteria.add(Restrictions.eq("vulnerability.isFalsePositive", false)); if (vulnTagIdList.size() > 0) { criteria.createAlias("vulnerability.tags", "tags"); criteria.add(Restrictions.in("tags.id", vulnTagIdList)); } if (teamIdList.isEmpty() || applicationIdList.isEmpty()) { if (!applicationIdList.isEmpty()) { criteria.add(Restrictions.in("id", applicationIdList)); } if (!teamIdList.isEmpty()) { criteria.add(Restrictions.in("organization.id", teamIdList)); } } else { criteria.add(Restrictions.or(Restrictions.in("id", applicationIdList), Restrictions.in("organization.id", teamIdList))); } if (!tagIdList.isEmpty()) { criteria.createAlias("tags", "tag"); criteria.add(Restrictions.in("tag.id", tagIdList)); } criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("id")) .add(Projections.alias(Projections.countDistinct("vulnerability.id"), "vulnCount"))); criteria.addOrder(Order.desc("vulnCount")); List<Integer> list = list(); List results = criteria.list(); int i = 0; for (Object result : results) { if (i++ >= numApps) { break; } Object[] resultArray = (Object[]) result; list.add((Integer) resultArray[0]); } if (list.isEmpty()) list = Arrays.asList(-1); return list; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationDao.java
License:Mozilla Public License
@Override public List<Map<String, Object>> retrieveAppsInfoMap(List<Integer> applicationIdList, List<Integer> vulnTagIds) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Application.class); criteria.createAlias("vulnerabilities", "vulnerability"); criteria.createAlias("organization", "team"); criteria.add(Restrictions.eq("active", true)); criteria.add(Restrictions.eq("vulnerability.active", true)); criteria.add(Restrictions.eq("vulnerability.isFalsePositive", false)); criteria.createAlias("vulnerability.genericSeverity", "severity"); if (applicationIdList.size() > 0) { criteria.add(Restrictions.in("id", applicationIdList)); }/* ww w .ja v a 2 s. co m*/ if (vulnTagIds.size() > 0) { criteria.createAlias("vulnerability.tags", "tags"); criteria.add(Restrictions.in("tags.id", vulnTagIds)); } criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("id"), "appId") .add(Projections.groupProperty("name"), "appName") .add(Projections.groupProperty("team.id"), "teamId") .add(Projections.groupProperty("team.name"), "teamName") .add(Projections.groupProperty("severity.intValue"), "severityIntValue") .add(Projections.groupProperty("severity.name"), "severityNameValue") .add(Projections.alias(Projections.countDistinct("vulnerability.id"), "vulnCount"))); criteria.addOrder(Order.desc("vulnCount")); criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List results = criteria.list(); return results; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateChannelTypeDao.java
License:Mozilla Public License
@Override public List<ChannelType> loadAllHasVulnMapping() { Criteria criteria = getSession().createCriteria(getClassReference()) .createAlias("channelVulnerabilities", "channelVulns").setProjection(Projections.projectionList() .add(Projections.groupProperty("name"), "name").add(Projections.groupProperty("id"), "id")); Order order = getOrder();//from ww w. ja v a 2 s . co m if (order != null) { criteria.addOrder(order); } criteria.setResultTransformer(Transformers.aliasToBean(ChannelType.class)); return criteria.list(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateEventDao.java
License:Mozilla Public License
private List<Event> retrieveGrouped(List<String> eventActions, User user, Date startTime, Date stopTime, Set<Integer> appIds, Set<Integer> teamIds, Set<Integer> vulnIds, Set<Integer> defectIds) { Criteria criteria = getEventCriteria(eventActions, user, startTime, stopTime, appIds, teamIds, vulnIds, defectIds);/* w w w. j a v a 2 s .c om*/ criteria.setProjection(Projections.projectionList().add(Projections.count("id").as("groupCount")) .add(Projections.groupProperty("eventAction").as("eventAction")) .add(Projections.groupProperty("scan").as("scan")) .add(Projections.groupProperty("deletedScanId").as("deletedScanId")) .add(Projections.min("date"), "date").add(Projections.groupProperty("application"), "application") .add(Projections.groupProperty("user"), "user")); criteria.setResultTransformer(Transformers.aliasToBean(Event.class)); List<Event> events = criteria.list(); for (Event event : events) { EventAction eventAction = event.getEventActionEnum(); EventAction groupedEventAction = eventAction.getGroupedEventAction(); String groupedEventActionString = groupedEventAction.name(); event.setEventAction(groupedEventActionString); } return events; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateScanDao.java
License:Mozilla Public License
/** * I want to get the earliest finding for each channeltype for each vulnerability * This solves the problem we had before where vulnerabilities with findings merged * over different scanners had incorrect statistics because firstFindingForVuln was used in stats * calculation/*w ww . j av a 2 s . c om*/ * * This involves testing uniqueness over the following fields: * - vuln ID * - scan ID (time, so we can sort) * - channel ID * * Then sort by date and take the earliest one. It will then go through another SQL statement * to make sure it's appropriate. We also need to cache this for multiple runs. * * Strategy-wise, we get all of these fields and hash them to create a key * This is a much smaller structure than hibernate objects. We want that to reduce the * memory footprint of this algorithm. * * With a caveat: some findings have a higher priority than others. If the finding already has a * counter, we want to include it in the list so that another finding merged to that finding doesn't * also get a counter, leading to that vulnerability getting double counted. Also, if one is marked * "firstFindingForVuln" we probably want that one. */ @Override public Collection<Integer> getEarliestFindingIdsForVulnPerChannel(List<Integer> appIds) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Finding.class) .createAlias("vulnerability", "vulnAlias").createAlias("vulnAlias.application", "appAlias") .createAlias("scan", "scanAlias").createAlias("scanAlias.applicationChannel", "appChannelAlias") .addOrder(Order.asc("scanAlias.importTime")).add(eq("appAlias.active", true)) .setProjection(Projections.projectionList().add(property("scanAlias.importTime")) // 0 .add(property("appChannelAlias.id")) // 1 .add(property("vulnAlias.id")) // 2 .add(property("id")) // 3 .add(property("firstFindingForVuln")) // 4 .add(property("hasStatisticsCounter")) // 5 ); if (appIds != null && !appIds.isEmpty()) { criteria.add(in("appAlias.id", appIds)); } List<Object[]> results = criteria.list(); // map makes more sense than array because the ints aren't small // this is the hashed (time + app channel + vuln ID) -> finding ID Map<Integer, Integer> resultMap = map(); for (Object[] singleResult : results) { // this boolean means that the vulnerability should be counted instead of // other vulnerabilities with the same hash. The singleResult[5] section // indicates that the finding has already been counted and helps us to not double-count // vulnerabilities. boolean highPriority = true; if (singleResult[4] != null && singleResult[5] != null) { highPriority = (Boolean) singleResult[4] || (Boolean) singleResult[5]; } int hash = hashIt(singleResult[0], singleResult[1], singleResult[2]); if (highPriority || !resultMap.containsKey(hash)) { // add the entry for the finding ID resultMap.put(hash, (Integer) singleResult[3]); } } return resultMap.values(); }