List of usage examples for org.hibernate.criterion Restrictions idEq
public static Criterion idEq(Object value)
From source file:org.xerela.provider.tools.PluginDetailServlet.java
License:Mozilla Public License
/** * Get the ExecutionData record by the requested executionId. * * @param executionId the execution ID/*from w ww . jav a 2 s . c om*/ * @return an ExecutionData object or <code>null</code> */ private ExecutionData getExecutionData(String executionId) { boolean ownTransaction = TransactionElf.beginOrJoinTransaction(); try { Session session = PluginsActivator.getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(ExecutionData.class); criteria.add(Restrictions.idEq(Integer.valueOf(executionId))); ExecutionData uniqueResult = (ExecutionData) criteria.uniqueResult(); return uniqueResult; } finally { if (ownTransaction) { TransactionElf.commit(); } } }
From source file:org.xerela.provider.tools.ScriptPluginDetailStreamer.java
License:Mozilla Public License
/** {@inheritDoc} */ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String recordId = req.getParameter(HTTP_RECORD_ID); boolean ownTransaction = TransactionElf.beginOrJoinTransaction(); try {/*from www .ja va 2 s .c o m*/ Session session = PluginsActivator.getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(ToolRunDetails.class); criteria.add(Restrictions.idEq(Integer.valueOf(recordId))); ToolRunDetails uniqueResult = (ToolRunDetails) criteria.uniqueResult(); String details = uniqueResult.getDetails(); if (details != null) { resp.setHeader("Content-type", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$ PrintWriter writer = resp.getWriter(); writer.print(details); } } finally { if (ownTransaction) { TransactionElf.commit(); } } }
From source file:owldb.util.HibernateUtil.java
License:Open Source License
/** * Retrieve all instances of the given class as a set in a Hibernate * transaction.//from ww w . ja v a2 s . co m * * @param <T> The type of the set * @param session The Hibernate session * @param clazz The clazz * @param associationPath A dot-seperated property path * @param idValue Apply an "equal" constraint to the identifier property * (associationPath) * @return All instances */ public <T> Set<T> retrieveSet(final Session session, final Class<T> clazz, final String associationPath, final Object idValue) { return this.retrieveSet(clazz, session.createCriteria(clazz).createCriteria(associationPath).add(Restrictions.idEq(idValue))); }
From source file:owldb.util.HibernateUtil.java
License:Open Source License
/** * Tests if an instance matching the given identity check exists. * /* w ww . ja va 2 s .c om*/ * @param session The Hibernate session * @param clazz The clazz of the instance * @param associationPath A dot-seperated property path * @param idValue Apply an "equal" constraint to the identifier property * (associationPath) * @return True if exists */ public boolean exists(final Session session, final Class<?> clazz, final String associationPath, final Object idValue) { return session.createCriteria(clazz).createCriteria(associationPath).add(Restrictions.idEq(idValue)) .uniqueResult() != null; }
From source file:pe.edu.upeu.configuration.SysDataAccess.java
public E getById(Serializable id) { E entidad = null;//from w w w . ja v a2s . c o m try { entidad = (E) (Serializable) getSession().createCriteria(this.persistentClass) .add(Restrictions.idEq(id)).uniqueResult(); } catch (HibernateException e) { this.logger.info("Mensage de Error en Al momento de Buscar por el Id " + e.getMessage()); } return entidad; }
From source file:pe.edu.upeu.configuration.SysDataAccess.java
public List<E> getListId(String id) { List<E> lista = null;/*from w ww.j av a 2 s. c o m*/ try { lista = getSession().createCriteria(this.persistentClass).add(Restrictions.idEq(id)).list(); if (lista == null) { lista = new ArrayList(); } } catch (HibernateException e) { this.logger.info("Mensage de Error en Al momento de Listar una Entidad " + e.getMessage()); } return lista; }
From source file:pe.edu.upeu.configuration.SysDataAccess.java
public List<E> getListId(Serializable id) { List<E> lista = null;// w w w .j av a2 s. c o m try { lista = getSession().createCriteria(this.persistentClass).add(Restrictions.idEq(id)).list(); if (lista == null) { lista = new ArrayList(); } } catch (HibernateException e) { this.logger.info("Mensage de Error en Al momento de Listar una Entidad " + e.getMessage()); } return lista; }
From source file:pe.edu.upeu.configuration.SysDataAccess.java
public List<E> getListId(int id) { List<E> lista = null;/*from w w w . j a v a 2 s . c o m*/ try { lista = getSession().createCriteria(this.persistentClass).add(Restrictions.idEq(id)).list(); if (lista == null) { lista = new ArrayList(); } } catch (HibernateException e) { this.logger.info("Mensage de Error en Al momento de Listar una Entidad " + e.getMessage()); } return lista; }
From source file:recetas.backend.model.DAOCategorias.java
@Override public String buscar(Integer id) throws IOException { Criteria cricri = this.session.createCriteria(Categorias.class).add(Restrictions.idEq(id)); ObjectMapper mapper = new ObjectMapper(); Categorias categoria = (Categorias) cricri.uniqueResult(); Hibernate.initialize(categoria.getRecetasList()); List<Recetas> recetas = categoria.getRecetasList(); ArrayList<Object> recetaList = new ArrayList<Object>(); for (Recetas r : recetas) { Receta rjson = new Receta(r); recetaList.add(rjson);/*from w w w .j av a 2s. c om*/ } Map<String, Object> map = new LinkedHashMap<String, Object>(); map.put("categoria", categoria); map.put("recetas", recetaList); this.closeCommit(); return mapper.writeValueAsString(map); }
From source file:recetas.backend.model.DAOImagenes.java
@Override public String buscar(Integer id) throws IOException { Criteria cricri = this.session.createCriteria(Imagenes.class).add(Restrictions.idEq(id)); ObjectMapper mapper = new ObjectMapper(); Imagenes imagen = (Imagenes) cricri.uniqueResult(); Map<String, Imagenes> map = Collections.singletonMap("imagen", imagen); this.closeCommit(); return mapper.writeValueAsString(map); }