Java Code Examples for org.hibernate.Criteria#list()
The following examples show how to use
org.hibernate.Criteria#list() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TagDataStatisticsResourceFacadeImp.java From AIDR with GNU Affero General Public License v3.0 | 6 votes |
@Override public List<TagData> getDataByCrisisAttributeLabelGranularity(String crisisCode, String attributeCode, String labelCode, Long granularity) { Criteria criteria = getCurrentSession().createCriteria(TagData.class); Criterion criterion = Restrictions.conjunction() .add(Restrictions.eq("crisisCode", crisisCode)) .add(Restrictions.eq("attributeCode", attributeCode)) .add(Restrictions.eq("labelCode", labelCode)) .add(Restrictions.eq("granularity", granularity)); criteria.add(criterion); try { List<TagData> objList = (List<TagData>) criteria.list(); return objList; } catch (HibernateException e) { logger.error("exception in getDataByCrisisAttributeLabelGranularity for crisisCode : " + crisisCode + " attributeCode : " + attributeCode + " labelCode : " + labelCode + " granularity : " + granularity, e); } return null; }
Example 2
Source File: CoreDBServiceFacadeImp.java From AIDR with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public List<E> getByCriteriaByOrder(Criterion criterion, String order, String[] orderBy, Integer count) { List<E> fetchedList = new ArrayList<E>(); Session session = getCurrentSession(); Criteria criteria = session.createCriteria(entityClass); criteria.add(criterion); for(int i = 0; i< orderBy.length; i++){ if (order != null && order.equalsIgnoreCase("desc")) { criteria.addOrder(Order.desc(orderBy[i])); } else { criteria.addOrder(Order.asc(orderBy[i])); } } if(count != null && count > 0){ criteria.setMaxResults(count); } try { fetchedList = criteria.list(); return fetchedList; } catch (Exception e) { logger.error("getByCriteriaWithLimit failed, criteria = " + criterion.toString(), e); throw new HibernateException("getByCriteriaByOrder failed, criteria = " + criterion.toString()); } }
Example 3
Source File: ConfidenceStatisticsResourceFacadeImp.java From AIDR with GNU Affero General Public License v3.0 | 6 votes |
@Override public List<ConfidenceData> getDataByCrisisAttributeLabelGranularity(String crisisCode, String attributeCode, String labelCode, Long granularity) { Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class); Criterion criterion = Restrictions.conjunction() .add(Restrictions.eq("crisisCode", crisisCode)) .add(Restrictions.eq("attributeCode", attributeCode)) .add(Restrictions.eq("labelCode", labelCode)) .add(Restrictions.eq("granularity", granularity)); criteria.add(criterion); try { List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list(); return objList; } catch (HibernateException e) { logger.error("exception", e); e.printStackTrace(); } return null; }
Example 4
Source File: ServerFactory.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * lookup System with specified digital server id which are foreign_entitled * * @param id the digital server id * @return server corresponding to the given id */ @SuppressWarnings("unchecked") public static Server lookupForeignSystemByDigitalServerId(String id) { Criteria criteria = getSession().createCriteria(Server.class); criteria.add(Restrictions.eq("digitalServerId", id)); for (Server server : (List<Server>) criteria.list()) { if (server.hasEntitlement(EntitlementManager.getByName("foreign_entitled"))) { return server; } } return null; }
Example 5
Source File: AbstractDaoImpl.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Override public List<E> findByCriteria(Criterion criterion, Integer count) { Criteria criteria = getCurrentSession().createCriteria(entityClass); criteria.add(criterion); if(count != null){ criteria.setMaxResults(count); } return criteria.list(); }
Example 6
Source File: LoginDaoImpl.java From Spring-MVC-Blueprints with MIT License | 5 votes |
@Transactional @SuppressWarnings("unchecked") @Override public List<HrmsLogin> getAdminUsers() { Session session = this.sessionFactory.getCurrentSession(); Criteria crit = session.createCriteria(HrmsLogin.class); crit.add(Restrictions.like("role","admin")); List<HrmsLogin> users = crit.list(); return users; }
Example 7
Source File: CoreDBServiceFacadeImp.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public List<E> getByCriteriaWithInnerJoinByOrder(Criterion criterion, String order, String[] orderBy, Integer count, String aliasTable, Criterion aliasCriterion) { Session session = getCurrentSession(); List<E> fetchedList = new ArrayList<E>(); //logger.info("Entity: " + entityClass + ", current Session = " + session); Criteria criteria = session.createCriteria(entityClass); criteria.add(criterion); criteria.createAlias(aliasTable, aliasTable, org.hibernate.sql.JoinType.INNER_JOIN).add(aliasCriterion); if (orderBy != null) { for(int i = 0; i< orderBy.length; i++){ if (order != null && order.equalsIgnoreCase("desc")) { criteria.addOrder(Order.desc(orderBy[i])); } else { criteria.addOrder(Order.asc(orderBy[i])); } } } if(count != null && count > 0){ criteria.setMaxResults(count); } try { fetchedList = criteria.list(); return fetchedList; } catch (Exception e) { logger.error("getByCriteriaWithInnerJoinByOrder failed, criteria = " + criterion.toString(), e); throw new HibernateException("getByCriteriaWithInnerJoinByOrder failed, criteria = " + criterion.toString()); } }
Example 8
Source File: BookDaoImpl.java From sdudoc with MIT License | 5 votes |
@Override public Pager<Book> searchByAuthor(String author, int pageNo, int pageSize) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Book.class); criteria.add(Restrictions.like("authors", "%"+author+"%")); long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue(); criteria.setProjection(null); // criteria.addOrder(Order.desc("clickTimes")); criteria.setFirstResult((pageNo - 1) * pageSize); criteria.setMaxResults(pageSize); List<Book> results = criteria.list(); Pager<Book> page=new Pager<Book>(pageSize, pageNo, recordTotal, results); return page; }
Example 9
Source File: HibernateStorage.java From sailfish-core with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public <T> List<T> getAllEntities(Class<T> entityClass, List<Criterion> criterions, String orderField, boolean orderAsc) { Session session = null; try { session = sessionFactory.openSession(); Criteria criteria = session.createCriteria(entityClass); for (Criterion criterion : criterions) { criteria.add(criterion); } criteria.addOrder(orderAsc ? Order.asc(orderField) : Order.desc(orderField)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); } finally { if(session != null) { session.close(); } } }
Example 10
Source File: SyllabusManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public Set<SyllabusData> findPublicSyllabusData() { HibernateCallback<List<SyllabusData>> hcb = session -> { Criteria crit = session.createCriteria(SyllabusDataImpl.class) .add(Expression.eq(VIEW, "yes")) .setFetchMode(ATTACHMENTS, FetchMode.EAGER); return crit.list(); }; return new HashSet<>(getHibernateTemplate().execute(hcb)); }
Example 11
Source File: AbstractDaoImpl.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public List<E> getMaxOrderByCriteria(Criterion criterion, String orderBy) { Criteria criteria = getCurrentSession().createCriteria(entityClass); criteria.add(criterion); criteria.addOrder(Order.desc(orderBy)); criteria.setMaxResults(1); try { return criteria.list(); } catch (HibernateException e) { logger.error("Error in getMaxOrderByCriteria for criteria : " + criteria.toString(),e); return null; } }
Example 12
Source File: HibernateDocumentDao.java From livingdoc-confluence with GNU General Public License v3.0 | 5 votes |
@Override public List<Reference> getAllReferences(Requirement requirement) { final Criteria crit = sessionService.getSession().createCriteria(Reference.class); crit.createAlias("requirement", "req"); crit.add(Restrictions.eq("req.name", requirement.getName())); crit.createAlias("req.repository", REPO); crit.add(Restrictions.eq(REPO_UID, requirement.getRepository().getUid())); @SuppressWarnings(SUPPRESS_UNCHECKED) List<Reference> references = crit.list(); HibernateLazyInitializer.initCollection(references); return references; }
Example 13
Source File: InventoryBookingDaoImpl.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
/** * @inheritDoc */ @Override protected Collection<InventoryBooking> handleFindByCourse(Long courseId, PSFVO psf) throws Exception { Criteria bookingCriteria = createBookingCriteria(); SubCriteriaMap criteriaMap = new SubCriteriaMap(InventoryBooking.class, bookingCriteria); if (courseId != null) { bookingCriteria.add(Restrictions.eq("course.id", courseId.longValue())); } CriteriaUtil.applyPSFVO(criteriaMap, psf); return bookingCriteria.list(); }
Example 14
Source File: HibernateRepositoryDao.java From livingdoc-confluence with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings(SUPPRESS_UNCHECKED) public List<Repository> getAll() { final Criteria criteria = sessionService.getSession().createCriteria(Repository.class); List<Repository> list = criteria.list(); HibernateLazyInitializer.initCollection(list); return list; }
Example 15
Source File: GetTaskAppointorCommand.java From uflo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public List<TaskAppointor> execute(Context context) { Criteria criteria=context.getSession().createCriteria(TaskAppointor.class); criteria.add(Restrictions.eq("processInstanceId", processInstanceId)); criteria.add(Restrictions.eq("taskNodeName", taskNodeName)); return criteria.list(); }
Example 16
Source File: BaseServiceImpl.java From TinyMooc with Apache License 2.0 | 5 votes |
@Transactional(readOnly = true) public List<?> getByPage(DetachedCriteria dCriteria, int pageSize) { int curPage = PageHelper.getCurPage(); Criteria criteria = dCriteria.getExecutableCriteria(getCurrentSession()); criteria.setFirstResult((curPage - 1) * pageSize); criteria.setMaxResults(pageSize); List<?> list = criteria.list(); return list; }
Example 17
Source File: SqlDaoBase.java From openwebflow with BSD 2-Clause "Simplified" License | 4 votes |
public <T> List<T> queryForObjects() throws Exception { Criteria criteria = getSession().createCriteria(_entityClass); return criteria.list(); }
Example 18
Source File: ChannelFactory.java From uyuni with GNU General Public License v2.0 | 4 votes |
/** * Returns list of channel architectures * @return list of channel architectures */ public static List<ChannelArch> getChannelArchitectures() { Session session = getSession(); Criteria criteria = session.createCriteria(ChannelArch.class); return criteria.list(); }
Example 19
Source File: K8sContainerStatusDaoImpl.java From kardio with Apache License 2.0 | 4 votes |
@Override public List<K8sContainerStatus> getAllContainersOfParent(String startDate, String endDate, int envId, String componentIdsStrg) throws ParseException { final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg); Date sDate = sdf1.parse(startDate); Date eDate = sdf1.parse(endDate); Session session = sessionFactory.openSession(); Criteria containerCriteria = session.createCriteria(K8sPodsContainersEntity.class, "contSts"); containerCriteria.createCriteria("contSts.component", "component"); containerCriteria.createCriteria("contSts.environment", "environment"); containerCriteria.add(Restrictions.ge("contSts.statusDate", sDate )); containerCriteria.add(Restrictions.le("contSts.statusDate", eDate )); if(envId != 0){ containerCriteria.add(Restrictions.eq("environment.environmentId", envId)); } containerCriteria.add(Restrictions.eq("environment.envLock", 0)); if(comIdList != null && comIdList.size() != 0){ containerCriteria.add(Restrictions.in("component.parentComponent.componentId", comIdList)); } ProjectionList projectionList = DaoUtil.getContainerStatusProjectionList(); containerCriteria.setProjection(projectionList); @SuppressWarnings("unchecked") List<Object[]> conList = containerCriteria.list(); List<K8sContainerStatus> contStatusList = new ArrayList<K8sContainerStatus>(); for (Object[] aRow : conList) { K8sContainerStatus contStatus = new K8sContainerStatus(); Integer comId = (Integer) aRow[0]; contStatus.setComponentId(comId); Date statsDate = (Date) aRow[1]; contStatus.setStatusDate(statsDate.toString()); long totalCont = (long) aRow[2]; contStatus.setTotalContainers(totalCont); contStatusList.add(contStatus); } session.close(); return contStatusList; }
Example 20
Source File: ReportDaoImpl.java From Spring-MVC-Blueprints with MIT License | 3 votes |
@Transactional @Override public Tblstudents getStudentId(String username) { Session session = this.sessionFactory.getCurrentSession(); Criteria crit = session.createCriteria(Tblstudents.class); crit.add(Restrictions.like("username",username)); List<Tblstudents> students = crit.list(); return students.get(0); }