List of usage examples for org.hibernate Criteria uniqueResult
public Object uniqueResult() throws HibernateException;
From source file:br.ufac.sion.dao.InscricaoFacade.java
@Override public int contaInscricoesByCargoAndLocalidade(FiltroInscritosRelatorio filtroRelatorio) { Session session = em.unwrap(Session.class); Criteria criteria = session.createCriteria(Inscricao.class); criteria.createAlias("cargoConcurso", "cc") .add(Restrictions.eq("cc.concurso", filtroRelatorio.getConcurso())); criteria.createAlias("candidato", "c"); if (filtroRelatorio.getCargo() != null && filtroRelatorio.getCargo().getId() != null) { criteria.add(Restrictions.eq("cargoConcurso", filtroRelatorio.getCargo())); }/*w w w.ja va2s . c o m*/ criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); Criterion confirmada = Restrictions.eq("status", SituacaoInscricao.CONFIRMADA); Criterion judice = Restrictions.eq("status", SituacaoInscricao.SUB_JUDICE); criteria.add(Restrictions.or(confirmada, judice)); criteria.setProjection(Projections.rowCount()); return ((Number) criteria.uniqueResult()).intValue(); }
From source file:br.ufg.calendario.dao.CalendarioDao.java
@Transactional(readOnly = true) public Calendario buscar(Integer ano) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Calendario.class); criteria.add(Restrictions.eq("ano", ano)); Calendario calendario = (Calendario) criteria.uniqueResult(); return calendario; }
From source file:br.ufg.calendario.dao.CalendarioDao.java
@Transactional(readOnly = true) public Calendario buscarAtivo() { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Calendario.class); criteria.add(Restrictions.eq("ativo", true)); Calendario calendario = (Calendario) criteria.uniqueResult(); return calendario; }
From source file:br.ufg.calendario.dao.UsuarioDao.java
@Transactional(readOnly = true) public Usuario buscarPorLogin(String login) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Usuario.class); criteria.add(Restrictions.eq("login", login)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Usuario usuario = (Usuario) criteria.uniqueResult(); if (usuario != null) { Hibernate.initialize(usuario.getPerfil()); }//from w ww . ja v a 2s. c o m return usuario; }
From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java
License:Open Source License
@Override public List<Category> getCategories(Category parent, Boolean includeUnclassified) throws PigeException { logger.debug("Rcupration des catgories..."); Transaction tx = null;// w w w . j a v a 2 s. co m List<Category> categories = null; Session session = null; try { session = PigeHibernateUtil.openSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(Category.class); if (parent != null) { logger.debug("category != null: " + parent.getName()); criteria.add(Restrictions.eq(Category.PARENT_REF, parent)); } else { criteria.add(Restrictions.isNull(Category.PARENT_REF)); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); categories = (List) criteria.addOrder(Order.asc(Category.NAME_REF)).list(); if (categories != null) { for (Category c : categories) { Criteria itemCrit = session.createCriteria(Item.class); itemCrit.createCriteria(Item.CATEGORIES_REF) .add(Restrictions.like(Category.PATH_REF, c.getPath(), MatchMode.START)); itemCrit.setProjection(Projections.distinct(Projections.rowCount())); c.setItemCount((Integer) itemCrit.uniqueResult()); } } // la racine seulement. if (includeUnclassified && parent == null) { Category unclassified = new Category(); unclassified.setId(Category.UNCLASSIFIED_CATEGORY_ID); Criteria itemCrit = session.createCriteria(Item.class); itemCrit.add(Restrictions.sizeEq(Item.CATEGORIES_REF, 0)); itemCrit.setProjection(Projections.distinct(Projections.rowCount())); unclassified.setItemCount((Integer) itemCrit.uniqueResult()); categories.add(unclassified); } tx.commit(); logger.debug("Rcupration russie!"); } catch (Exception hex) { logger.error(hex); if (tx != null) { tx.rollback(); } } finally { if (session != null) { session.close(); } } return categories; }
From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java
License:Open Source License
@Override public void createCategory(Category category, Category parent) throws PigeException { logger.debug("Ajout d'une catgorie..."); Transaction tx = null;//from ww w .jav a 2s .co m Session session = null; try { session = PigeHibernateUtil.openSession(); tx = session.beginTransaction(); if (parent != null) { Criteria criteria = session.createCriteria(Category.class) .add(Restrictions.eq(Category.ID_REF, parent.getId())); parent = (Category) criteria.uniqueResult(); parent.addChild(category); category.updatePath(); logger.debug("Path de la catgorie nouvellement ajoute: " + category.getPath()); } else { category.updatePath(); session.save(category); } tx.commit(); logger.debug("Ajout russi!"); } catch (Exception hex) { logger.error(hex); if (tx != null) { tx.rollback(); } } finally { if (session != null) { session.close(); } } }
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractGenericEntityDAO.java
License:Apache License
public final T tryGetByTechId(final TechId techId, String... connections) throws DataAccessException { assert techId != null : "Technical identifier unspecified."; final Criteria criteria = getSession().createCriteria(getEntityClass()); criteria.add(Restrictions.eq("id", techId.getId())); for (String connection : connections) { criteria.setFetchMode(connection, FetchMode.JOIN); }/*from w w w . j av a2 s .com*/ final T result = tryGetEntity(criteria.uniqueResult()); if (operationLog.isDebugEnabled()) { operationLog.debug( String.format("%s(%s): '%s'.", MethodUtils.getCurrentMethod().getName(), techId, result)); } return result; }
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AuthorizationGroupDAO.java
License:Apache License
public AuthorizationGroupPE tryFindByCode(String code) { final Criteria criteria = getSession().createCriteria(AuthorizationGroupPE.class); criteria.add(Restrictions.eq("code", CodeConverter.tryToDatabase(code))); criteria.add(Restrictions.eq("databaseInstance", getDatabaseInstance())); return (AuthorizationGroupPE) criteria.uniqueResult(); }
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.DataStoreDAO.java
License:Apache License
public DataStorePE tryToFindDataStoreByCode(String dataStoreCode) { assert dataStoreCode != null : "Unspecified data store code."; final Criteria criteria = getSession().createCriteria(DataStorePE.class); criteria.add(Restrictions.eq("code", CodeConverter.tryToDatabase(dataStoreCode))); return (DataStorePE) criteria.uniqueResult(); }
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.EntityPropertyTypeDAO.java
License:Apache License
public EntityTypePropertyTypePE tryFindAssignment(EntityTypePE entityType, PropertyTypePE propertyType) { assert entityType != null : "Unspecified entity type."; assert propertyType != null : "Unspecified property type."; final Criteria criteria = getSession().createCriteria(getEntityTypePropertyTypeAssignmentClass()); criteria.add(Restrictions.eq("propertyTypeInternal", propertyType)); criteria.add(Restrictions.eq("entityTypeInternal", entityType)); final EntityTypePropertyTypePE etpt = (EntityTypePropertyTypePE) criteria.uniqueResult(); return etpt;// w w w. j a va2 s . c om }