List of usage examples for org.hibernate.criterion ProjectionList add
public ProjectionList add(Projection projection)
From source file:org.opennms.netmgt.dao.hibernate.AssetRecordDaoHibernate.java
License:Open Source License
@Override public List<OnmsAssetRecord> getDistinctProperties() { DetachedCriteria criteria = DetachedCriteria.forClass(OnmsAssetRecord.class); ProjectionList projList = Projections.projectionList(); // projList.add(Projections.alias(Projections.property("geolocation"), "geolocation")); projList.add(Projections.alias(Projections.property("additionalhardware"), "additionalhardware")); projList.add(Projections.alias(Projections.property("geolocation.address1"), "address1")); projList.add(Projections.alias(Projections.property("geolocation.address2"), "address2")); projList.add(Projections.alias(Projections.property("admin"), "admin")); projList.add(Projections.alias(Projections.property("assetNumber"), "assetNumber")); projList.add(Projections.alias(Projections.property("autoenable"), "autoenable")); projList.add(Projections.alias(Projections.property("building"), "building")); projList.add(Projections.alias(Projections.property("category"), "category")); projList.add(Projections.alias(Projections.property("circuitId"), "circuitId")); projList.add(Projections.alias(Projections.property("geolocation.city"), "city")); projList.add(Projections.alias(Projections.property("comment"), "comment")); projList.add(Projections.alias(Projections.property("connection"), "connection")); projList.add(Projections.alias(Projections.property("geolocation.longitude"), "longitude")); projList.add(Projections.alias(Projections.property("geolocation.latitude"), "latitude")); projList.add(Projections.alias(Projections.property("cpu"), "cpu")); projList.add(Projections.alias(Projections.property("department"), "department")); projList.add(Projections.alias(Projections.property("description"), "description")); projList.add(Projections.alias(Projections.property("displayCategory"), "displayCategory")); projList.add(Projections.alias(Projections.property("division"), "division")); projList.add(Projections.alias(Projections.property("enable"), "enable")); projList.add(Projections.alias(Projections.property("floor"), "floor")); projList.add(Projections.alias(Projections.property("hdd1"), "hdd1")); projList.add(Projections.alias(Projections.property("hdd2"), "hdd2")); projList.add(Projections.alias(Projections.property("hdd3"), "hdd3")); projList.add(Projections.alias(Projections.property("hdd4"), "hdd4")); projList.add(Projections.alias(Projections.property("hdd5"), "hdd5")); projList.add(Projections.alias(Projections.property("hdd6"), "hdd6")); projList.add(Projections.alias(Projections.property("inputpower"), "inputpower")); projList.add(Projections.alias(Projections.property("lease"), "lease")); projList.add(Projections.alias(Projections.property("maintcontract"), "maintcontract")); projList.add(Projections.alias(Projections.property("manufacturer"), "manufacturer")); projList.add(Projections.alias(Projections.property("modelNumber"), "modelNumber")); projList.add(Projections.alias(Projections.property("notifyCategory"), "notifyCategory")); projList.add(Projections.alias(Projections.property("numpowersupplies"), "numpowersupplies")); projList.add(Projections.alias(Projections.property("operatingSystem"), "operatingSystem")); projList.add(Projections.alias(Projections.property("pollerCategory"), "pollerCategory")); projList.add(Projections.alias(Projections.property("port"), "port")); projList.add(Projections.alias(Projections.property("rack"), "rack")); projList.add(Projections.alias(Projections.property("ram"), "ram")); projList.add(Projections.alias(Projections.property("region"), "region")); projList.add(Projections.alias(Projections.property("room"), "room")); projList.add(Projections.alias(Projections.property("serialNumber"), "serialNumber")); projList.add(Projections.alias(Projections.property("slot"), "slot")); projList.add(Projections.alias(Projections.property("snmpcommunity"), "snmpcommunity")); projList.add(Projections.alias(Projections.property("geolocation.state"), "state")); projList.add(Projections.alias(Projections.property("storagectrl"), "storagectrl")); projList.add(Projections.alias(Projections.property("supportPhone"), "supportPhone")); projList.add(Projections.alias(Projections.property("thresholdCategory"), "thresholdCategory")); projList.add(Projections.alias(Projections.property("username"), "username")); projList.add(Projections.alias(Projections.property("vendor"), "vendor")); projList.add(Projections.alias(Projections.property("vendorAssetNumber"), "vendorAssetNumber")); projList.add(Projections.alias(Projections.property("vendorFax"), "vendorFax")); projList.add(Projections.alias(Projections.property("vendorPhone"), "vendorPhone")); projList.add(Projections.alias(Projections.property("geolocation.zip"), "zip")); projList.add(Projections.alias(Projections.property("vmwareManagedObjectId"), "vmwareManagedObjectId")); projList.add(Projections.alias(Projections.property("vmwareManagedEntityType"), "vmwareManagedEntityType")); projList.add(Projections.alias(Projections.property("vmwareManagementServer"), "vmwareManagementServer")); projList.add(Projections.alias(Projections.property("vmwareTopologyInfo"), "vmwareTopologyInfo")); projList.add(Projections.alias(Projections.property("vmwareState"), "vmwareState")); criteria.setProjection(Projections.distinct(projList)); criteria.setResultTransformer(Transformers.aliasToBean(OnmsAssetRecord.class)); @SuppressWarnings("unchecked") List<OnmsAssetRecord> result = (List<OnmsAssetRecord>) getHibernateTemplate().findByCriteria(criteria); return result; }
From source file:org.owasp.dependencytrack.dao.VulnerabilityDao.java
License:Open Source License
/** * Returns a list of Vulnerability objects for LibraryVersions * that have a dependency of the specified ApplicationVersion. * * @param applicationVersion The ApplicationVersion to retrieve vulnerability for * @return a List of Vulnerability objects *///from ww w . jav a2 s .c om @SuppressWarnings("unchecked") public List<VulnerableComponent> getVulnerableComponents(ApplicationVersion applicationVersion) { final Query query = sessionFactory.getCurrentSession() .createQuery("from ApplicationDependency where applicationVersion=:version"); query.setParameter("version", applicationVersion); final List<VulnerableComponent> vulnerableComponents = new ArrayList<>(); // Retrieve all of the library versions from the specified application version final List<LibraryVersion> libvers = new ArrayList<>(); final List<ApplicationDependency> deps = query.list(); for (ApplicationDependency dep : deps) { libvers.add(dep.getLibraryVersion()); } // Iterate through the library versions looking for scan results for (LibraryVersion libraryVersion : libvers) { final Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ScanResult.class); criteria.add(Expression.eq("libraryVersion", libraryVersion)); final ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("libraryVersion")); projList.add(Projections.property("vulnerability")); criteria.setProjection(Projections.distinct(projList)); final List<Object[]> results = criteria.list(); final List<Vulnerability> vulns = new ArrayList<>(); for (Object[] result : results) { for (Object object : result) { if (object instanceof Vulnerability) { vulns.add((Vulnerability) object); } } } final VulnerableComponent vulnerableComponent = new VulnerableComponent(); vulnerableComponent.setLibraryVersion(libraryVersion); vulnerableComponent.setVulnerabilities(vulns); // Add the VulnerableComponent to the list of vulnerableComponents to return vulnerableComponents.add(vulnerableComponent); } return vulnerableComponents; }
From source file:org.owasp.dependencytrack.dao.VulnerabilityDao.java
License:Open Source License
public List<Vulnerability> getVulnsForLibraryVersion(LibraryVersion libraryVersion) { //todo: remove criteria and replace with HQL final Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ScanResult.class); criteria.add(Expression.eq("libraryVersion", libraryVersion)); final ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("libraryVersion")); projList.add(Projections.property("vulnerability")); criteria.setProjection(Projections.distinct(projList)); final List<Object[]> results = criteria.list(); final List<Vulnerability> vulns = new ArrayList<>(); for (Object[] result : results) { for (Object object : result) { if (object instanceof Vulnerability) { vulns.add((Vulnerability) object); }//from w w w . j a v a 2 s .com } } return vulns; }
From source file:org.owasp.dependencytrack.dao.VulnerabilityDaoImpl.java
License:Open Source License
/** * Returns a list of Vulnerability objects for LibraryVersions that have a * dependency of the specified ApplicationVersion. * * @param applicationVersion//from ww w.j av a 2 s . c o m * The ApplicationVersion to retrieve vulnerability for * @return a List of Vulnerability objects */ @SuppressWarnings("unchecked") public List<VulnerableComponent> getVulnerableComponents(final ApplicationVersion applicationVersion) { final Session session = getSession(); final List<VulnerableComponent> vulnerableComponents = new ArrayList<>(); // Retrieve all of the library versions from the specified application version final List<LibraryVersion> libvers = new ArrayList<>(); final Query query = session.createQuery("from ApplicationDependency where applicationVersion=:version"); query.setParameter("version", applicationVersion); final List<ApplicationDependency> deps = query.list(); for (ApplicationDependency dep : deps) { libvers.add(dep.getLibraryVersion()); } // Iterate through the library versions looking for scan results for (LibraryVersion libraryVersion : libvers) { final Criteria criteria = session.createCriteria(ScanResult.class); criteria.add(Restrictions.eq("libraryVersion", libraryVersion)); final ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("libraryVersion")); projList.add(Projections.property("vulnerability")); criteria.setProjection(Projections.distinct(projList)); final List<Object[]> results = criteria.list(); final List<Vulnerability> vulns = new ArrayList<>(); for (Object[] result : results) { for (Object object : result) { if (object instanceof Vulnerability) { vulns.add((Vulnerability) object); } } } final VulnerableComponent vulnerableComponent = new VulnerableComponent(); vulnerableComponent.setLibraryVersion(libraryVersion); vulnerableComponent.setVulnerabilities(vulns); // Add the VulnerableComponent to the list of vulnerableComponents to return vulnerableComponents.add(vulnerableComponent); } return vulnerableComponents; }
From source file:org.owasp.dependencytrack.dao.VulnerabilityDaoImpl.java
License:Open Source License
public List<Vulnerability> getVulnsForLibraryVersion(final LibraryVersion libraryVersion) { final Session session = getSession(); final Criteria criteria = session.createCriteria(ScanResult.class); criteria.add(Restrictions.eq("libraryVersion", libraryVersion)); final ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("libraryVersion")); projList.add(Projections.property("vulnerability")); criteria.setProjection(Projections.distinct(projList)); final List<Object[]> results = criteria.list(); final List<Vulnerability> vulns = new ArrayList<>(); for (Object[] result : results) { for (Object object : result) { if (object instanceof Vulnerability) { vulns.add((Vulnerability) object); }/*from w ww . ja v a2 s. c om*/ } } return vulns; }
From source file:org.remus.marketplace.scheduling.GenerateStatisticsJob.java
License:Open Source License
private void createClickStatistics(Integer id, File folder, Node node, Calendar instance) { Map<Date, Integer> map = new HashMap<Date, Integer>(); for (int i = 0, n = month; i < n; i++) { Calendar instance2 = Calendar.getInstance(); instance2.setTime(new Date()); instance2.add(Calendar.MONTH, i * -1); map.put(instance2.getTime(), 0); }//from w w w. j a v a 2s.com AdvancedCriteria criteria = new AdvancedCriteria() .addRestriction(Restrictions.between(Clickthrough.TIME, instance.getTime(), new Date())) .addRestriction(Restrictions.eq(Clickthrough.NODE, node)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.count(Clickthrough.NODE)); projectionList .add(Projections.sqlGroupProjection("month({alias}.time) as month, year({alias}.time) as year", "month({alias}.time), year({alias}.time)", new String[] { "month", "year" }, new Type[] { Hibernate.INTEGER, Hibernate.INTEGER })); criteria.setProjection(projectionList); List<Object> query = clickthroughDao.query(criteria); for (Object object : query) { Object[] data = (Object[]) object; Integer count = (Integer) data[0]; Integer month = (Integer) data[1]; Integer year = (Integer) data[2]; Set<Date> keySet = map.keySet(); for (Date date : keySet) { Calendar instance2 = Calendar.getInstance(); instance2.setTime(date); if (instance2.get(Calendar.YEAR) == year && instance2.get(Calendar.MONTH) == month - 1) { map.put(date, count); } } } DefaultCategoryDataset data = new DefaultCategoryDataset(); List<Date> keySet = new ArrayList<Date>(map.keySet()); Collections.sort(keySet, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); for (Date date : keySet) { Integer integer = map.get(date); Calendar instance2 = Calendar.getInstance(); instance2.setTime(date); int year = instance2.get(Calendar.YEAR); int month = instance2.get(Calendar.MONTH) + 1; data.addValue(integer, "Column1", month + "-" + year); } JFreeChart createBarChart = ChartFactory.createBarChart("Clicks", "Month", "", data, PlotOrientation.VERTICAL, false, false, false); File file = new File(folder, "clicks_" + id + ".png"); if (file.exists()) { file.delete(); } try { ChartUtilities.saveChartAsPNG(file, createBarChart, 500, 300); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.remus.marketplace.scheduling.GenerateStatisticsJob.java
License:Open Source License
private void createDownloadStatistics(Integer id, File folder, Node node, Calendar instance) { Map<Date, Integer> map = new HashMap<Date, Integer>(); for (int i = 0, n = month; i < n; i++) { Calendar instance2 = Calendar.getInstance(); instance2.setTime(new Date()); instance2.add(Calendar.MONTH, i * -1); map.put(instance2.getTime(), 0); }/*from w w w . ja va2 s. c om*/ AdvancedCriteria criteria = new AdvancedCriteria() .addRestriction(Restrictions.between(Download.TIME, instance.getTime(), new Date())) .addRestriction(Restrictions.eq(Download.NODE, node)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.count(Download.NODE)); projectionList .add(Projections.sqlGroupProjection("month({alias}.time) as month, year({alias}.time) as year", "month({alias}.time), year({alias}.time)", new String[] { "month", "year" }, new Type[] { Hibernate.INTEGER, Hibernate.INTEGER })); criteria.setProjection(projectionList); List<Object> query = downloadDao.query(criteria); for (Object object : query) { Object[] data = (Object[]) object; Integer count = (Integer) data[0]; Integer month = (Integer) data[1]; Integer year = (Integer) data[2]; Set<Date> keySet = map.keySet(); for (Date date : keySet) { Calendar instance2 = Calendar.getInstance(); instance2.setTime(date); if (instance2.get(Calendar.YEAR) == year && instance2.get(Calendar.MONTH) == month - 1) { map.put(date, count); } } } DefaultCategoryDataset data = new DefaultCategoryDataset(); List<Date> keySet = new ArrayList<Date>(map.keySet()); Collections.sort(keySet, new Comparator<Date>() { @Override public int compare(Date o1, Date o2) { return o1.compareTo(o2); } }); for (Date date : keySet) { Integer integer = map.get(date); Calendar instance2 = Calendar.getInstance(); instance2.setTime(date); int year = instance2.get(Calendar.YEAR); int month = instance2.get(Calendar.MONTH) + 1; data.addValue(integer, "Column1", month + "-" + year); } JFreeChart createBarChart = ChartFactory.createBarChart("Downloads", "Month", "", data, PlotOrientation.VERTICAL, false, false, false); File file = new File(folder, "download_" + id + ".png"); if (file.exists()) { file.delete(); } try { ChartUtilities.saveChartAsPNG(file, createBarChart, 500, 300); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionStatAccessImpl.java
License:Apache License
private void addStatProjection(Criteria criteria) throws PersistenceException { ProjectionList projList = Projections.projectionList(); projList.add(Projections.rowCount()); for (ColumnStatRequest<T> column : statRequest) { if (column.isFlag(COUNT)) { projList.add(Projections.count(column.getColumn().getName())); }/*from www .j av a2s. c o m*/ if (column.isFlag(MIN)) { projList.add(Projections.min(column.getColumn().getName())); } if (column.isFlag(MAX)) { projList.add(Projections.max(column.getColumn().getName())); } if (column.isFlag(AVERAGE)) { projList.add(Projections.avg(column.getColumn().getName())); } if (column.isFlag(SUM)) { projList.add(Projections.sum(column.getColumn().getName())); } if (column.isFlag(GROUP_BY_VAL)) { projList.add(Projections.groupProperty(column.getColumn().getName())); } // Time groups for (ColumnStatType flag : TIME_GROUPS) { if (column.isFlag(flag)) { projList.add(makeTimeGroupBy(column, flag, criteria)); } } } criteria.setProjection(projList); }
From source file:org.shredzone.cilla.core.repository.impl.PageDaoHibImpl.java
License:Open Source License
@Transactional(readOnly = true) @Override//from w w w .java2 s. co m public Date[] fetchMinMaxModification() { Date now = new Date(); Criteria crit = getCurrentSession().createCriteria(Page.class); crit.add(Restrictions.and(Restrictions.isNotNull("publication"), Restrictions.le("publication", now))); crit.add(Restrictions.or(Restrictions.isNull("expiration"), Restrictions.gt("expiration", now))); crit.add(Restrictions.eq("hidden", false)); ProjectionList proj = Projections.projectionList(); proj.add(Projections.min(pageOrder.getColumn())); proj.add(Projections.max(pageOrder.getColumn())); crit.setProjection(proj); Object[] row = (Object[]) crit.uniqueResult(); Date[] result = new Date[2]; result[0] = (Date) row[0]; result[1] = (Date) row[1]; return result; }
From source file:org.wise.portal.dao.ideabasket.impl.HibernateIdeaBasketDao.java
License:Open Source License
/** * Get all the latest IdeaBaskets with the given run id * //from ww w.j a va 2s. co m * we will basically be performing this query * select * from vle_database.ideaBasket i where id in(SELECT max(id) FROM vle_database.ideaBasket i where runid=<insert runId> group by workgroupid) * * @param runId the id of the run * @return all the latest IdeaBaskets for a run id */ @SuppressWarnings("unchecked") @Transactional(readOnly = true) public List<IdeaBasket> getLatestIdeaBasketsForRunId(long runId) { Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession(); /* * create a projection that will give us the latest idea basket id * for each workgroup id in the run. the projection will return * an array of array objects that will look like [id, workgroupId]. * each workgroup id will only appear once. */ ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.max("id")); projectionList.add(Projections.groupProperty("workgroupId")); //this first query will filter on the runId and the projection List latestIdeaBasketIdsProjection = session.createCriteria(IdeaBasket.class) .add(Restrictions.eq("runId", runId)).setProjection(projectionList).list(); //the list that will contain all the idea basket ids we want List<Long> ideaBasketIds = new ArrayList<Long>(); //loop through all the results from our first query for (int x = 0; x < latestIdeaBasketIdsProjection.size(); x++) { //get the idea basket id Object[] projection = (Object[]) latestIdeaBasketIdsProjection.get(x); Long ideaBasketId = (Long) projection[0]; ideaBasketIds.add(ideaBasketId); } List<IdeaBasket> result = new ArrayList<IdeaBasket>(); if (ideaBasketIds.size() > 0) { //this second query will retrieve all the idea basket ids we retrieved from the first query result = session.createCriteria(IdeaBasket.class).add(createIdOrCriterion(ideaBasketIds, 0)).list(); } return result; }