List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
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 ww w .j a v a 2 s .c om 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);//w ww . ja v a 2 s . c o 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")); }/*from ww w . j a va 2 s .c o m*/ s.close(); return list; }
From source file:com.court.controller.ReportFormFxmlController.java
private List<LoanPayCheque> getCollectionInvoice() { Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(LoanPayCheque.class); c.setProjection(Projections.property("invoCode")); c.setResultTransformer(Transformers.aliasToBean(LoanPayCheque.class)); List<LoanPayCheque> list = c.list(); s.close();// w w w.j a v a 2 s .c om return list; }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
/** * Retrieve all from Device Inventory./*w ww .jav a 2 s . c o m*/ * * @return list of entities */ @SuppressWarnings("unchecked") public List<DeviceInventoryEntity> getAllDeviceInventory(List<SortParamParser.SortInfo> sortInfos, List<FilterParamParser.FilterInfo> filterInfos, PaginationInfo paginationInfo) throws AsmManagerDAOException { Session session = null; Transaction tx = null; List<DeviceInventoryEntity> entityList = new ArrayList<DeviceInventoryEntity>(); try { // NOTE[fcarta] need to at this here so we dont nest the session / transaction List<String> refIdsServices = ListUtils.EMPTY_LIST; List<String> refIdsGroups = ListUtils.EMPTY_LIST; List<String> refIdsAllGroups = ListUtils.EMPTY_LIST; boolean spFilterSet = false; boolean spGlobalFilterSet = false; if (CollectionUtils.isNotEmpty(filterInfos)) { for (FilterParamParser.FilterInfo filterInfo : filterInfos) { // if there is a service filter then grab the ref id for the device if (StringUtils.equals(SERVICE_FILTER_PARAM, filterInfo.getColumnName())) { refIdsServices = getRefIdsOfDevicesByDeploymentIds(filterInfo.getColumnValue()); } else if (StringUtils.equals(SERVERPOOL_FILTER_PARAM, filterInfo.getColumnName())) { if (filterInfo.getColumnValue() .contains(ServiceTemplateSettingIDs.SERVICE_TEMPLATE_SERVER_POOL_GLOBAL_ID)) { refIdsAllGroups = getRefIdsOfDevicesByGroupIds(filterInfo.getColumnValue()); spGlobalFilterSet = true; } else { refIdsGroups = getRefIdsOfDevicesByGroupIds(filterInfo.getColumnValue()); spFilterSet = true; } } } } session = _dao._database.getNewSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(DeviceInventoryEntity.class); if (sortInfos != null) { BaseDAO.addSortCriteria(criteria, sortInfos); } if (filterInfos != null) { final List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos, DeviceInventoryEntity.class); if (CollectionUtils.isNotEmpty(notFound)) { for (FilterParamParser.FilterInfo filterInfo : notFound) { // if this is a filter by service then we need to get the subset of ref ids for devices // only in the deployment id subset passed if (StringUtils.equals(SERVICE_FILTER_PARAM, filterInfo.getColumnName())) { if (CollectionUtils.isNotEmpty(refIdsServices)) { criteria.add(Restrictions.in("refId", refIdsServices)); } } else if (StringUtils.equals(SERVERPOOL_FILTER_PARAM, filterInfo.getColumnName())) { if (spGlobalFilterSet) { if (refIdsAllGroups.isEmpty()) { // this means there are no servers in any server pool - all are in Global criteria.add(Restrictions.sqlRestriction("(1=1)")); } else { criteria.add(Restrictions.not(Restrictions.in("refId", refIdsAllGroups))); } } else if (spFilterSet) { if (refIdsGroups.isEmpty()) { criteria.add(Restrictions.sqlRestriction("(1=0)")); } else { criteria.add(Restrictions.in("refId", refIdsGroups)); } } } else { criteria.createAlias("deviceInventoryEntity", "deviceInventoryEntityAlias"); criteria.add(Restrictions.eq("deviceInventoryEntityAlias.deviceKey", filterInfo.getColumnName())); if (filterInfo.getColumnValue().size() == 1) { criteria.add(Restrictions.eq("deviceInventoryEntityAlias.deviceValue", filterInfo.getColumnValue().get(0))); } else if (filterInfo.getColumnValue().size() > 1) { criteria.add(Restrictions.in("deviceInventoryEntityAlias.deviceValue", filterInfo.getColumnValue())); } } } } } if (paginationInfo != null) { int offset = paginationInfo.getOffset(); int limit = paginationInfo.getLimit(); int pageSize = limit; criteria.setFirstResult(offset); criteria.setMaxResults(pageSize); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); entityList = criteria.list(); this.setFirmwareBasedOnDeployment(entityList); tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get all devices in inventory: " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get all devices: " + ex); } throw new AsmManagerDAOException("Caught exception during get all devices in inventory: ", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get all devices: " + ex); } } return entityList; }
From source file:com.dell.asm.asmcore.asmmanager.db.ServiceTemplateDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ServiceTemplateEntity> getAllTemplates(List<SortParamParser.SortInfo> sortInfos, List<FilterParamParser.FilterInfo> filterInfos, int offset, int pageSize) { Session session = null;// w w w . j av a2 s . c o m Transaction tx = null; List<ServiceTemplateEntity> entityList = new ArrayList<>(); try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(ServiceTemplateEntity.class); BaseDAO.addSortCriteria(criteria, sortInfos); List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos, ServiceTemplateEntity.class); //criteria.setFirstResult((pageNumber - 1) * pageSize); if (offset >= 0) criteria.setFirstResult(offset); if (pageSize >= 0) criteria.setMaxResults(pageSize); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); entityList = criteria.list(); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get all templates: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get all templates: " + ex); } throw new AsmManagerInternalErrorException("Get All templates", "TemplateDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get all devices: " + ex); } } logger.warn("Template DAO get all templates size: " + entityList.size()); return entityList; }
From source file:com.dell.asm.asmcore.asmmanager.db.ServiceTemplateDAO.java
License:Open Source License
/** * Helper method to get total number of records with filter parameters * * @param filterInfos - List for holding filtering information parsed from filter query parameter value * @return int - total number of records *///from w w w . j a va2 s .c om public Integer getTotalRecords(List<FilterParamParser.FilterInfo> filterInfos) { long totalRecords = 0; Session session = null; Transaction tx = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(ServiceTemplateEntity.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); BaseDAO.addFilterCriteria(criteria, filterInfos, ServiceTemplateEntity.class); totalRecords = (long) criteria.setProjection(Projections.rowCount()).uniqueResult(); tx.commit(); } catch (Exception e) { if (tx != null) try { tx.rollback(); } catch (Exception e2) { logger.warn("Error during rollback", e2); } } finally { try { if (session != null) session.close(); } catch (Exception e2) { logger.warn("Error during session close", e2); } } logger.warn("Template DAO getTotalRecords size: " + totalRecords); return (int) totalRecords; }
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)); }//from w w w. j av a2 s . c om 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 w w w. ja v a2 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);/*from ww w . ja v a2s . 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; }