List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:test.eurocarbdb.dataaccess.core.SubQueryTest.java
License:Open Source License
public void canSimpleDetachedSubQuery() { super.setup(); //Criteria subcriteria = em.createQuery( GlycanSequence.class ).setMaxResults( 20 ); DetachedCriteria subcriteria = DetachedCriteria.forClass(GlycanSequence.class); DetachedCriteria criteria;//from w w w .j av a 2s . com criteria = DetachedCriteria.forClass(GlycanSequence.class); // criteria.add( Restrictions.lt( "glycanSequenceId", 100)); DetachedCriteria bc_crit = criteria.createCriteria("glycanContexts"); //DetachedCriteria bc_crit = DetachedCriteria.forClass( GlycanSequenceContext.class ); //criteria.createCriteria("glycanContexts"); bc_crit.add(Restrictions.gt("glycanSequenceContextId", 0)); bc_crit.setProjection(Projections.property("glycanSequenceContextId")); criteria.add(Subqueries.propertyIn("glycanSequenceContextId", bc_crit)); criteria.setProjection(Projections.distinct(Projections.property("glycanSequenceId"))); subcriteria.add(Subqueries.propertyIn("glycanSequenceId", criteria)); //System.out.println(subcriteria.list().size()); //subcriteria.getExecutableCriteria(((HibernateEntityManager) em).getHibernateSession()).setMaxResults(20).list(); super.teardown(); }
From source file:to.etc.domui.hibernate.model.CriteriaCreatingVisitor.java
License:Open Source License
@Override public void visitPropertyComparison(QPropertyComparison n) throws Exception { QOperatorNode rhs = n.getExpr();/* w ww . ja v a 2 s.com*/ String name = n.getProperty(); QLiteral lit = null; if (rhs.getOperation() == QOperation.LITERAL) { lit = (QLiteral) rhs; } else if (rhs.getOperation() == QOperation.SELECTION_SUBQUERY) { handlePropertySubcriteriaComparison(n); return; } else throw new IllegalStateException( "Unknown operands to " + n.getOperation() + ": " + name + " and " + rhs.getOperation()); //-- If prop refers to some relation (dotted pair): name = parseSubcriteria(name); Criterion last = null; switch (n.getOperation()) { default: throw new IllegalStateException("Unexpected operation: " + n.getOperation()); case EQ: if (lit.getValue() == null) { last = Restrictions.isNull(name); break; } last = Restrictions.eq(name, lit.getValue()); break; case NE: if (lit.getValue() == null) { last = Restrictions.isNotNull(name); break; } last = Restrictions.ne(name, lit.getValue()); break; case GT: last = Restrictions.gt(name, lit.getValue()); break; case GE: last = Restrictions.ge(name, lit.getValue()); break; case LT: last = Restrictions.lt(name, lit.getValue()); break; case LE: last = Restrictions.le(name, lit.getValue()); break; case LIKE: handleLikeOperation(name, m_targetProperty, lit.getValue()); return; case ILIKE: last = Restrictions.ilike(name, lit.getValue()); break; } m_last = last; }
From source file:ua.gov.uz.pv.entity.controller.worstKMController.java
public void testDeviation() { List<Deviation> result = new ArrayList<Deviation>(); session = HibernateUtil.getSessionFactory().openSession(); result = session.createCriteria(Deviation.class).add(Restrictions.gt("dateMeasuring", getStartDate())) .list();//from ww w. j a va2s .c o m for (Deviation d : result) { // DeviationDraw dd = new DeviationDraw(d); // dd.draw(); } session.close(); }
From source file:ubc.pavlab.aspiredb.server.dao.CriteriaBuilder.java
License:Apache License
/** * @param operator/*w ww . j a va 2 s. c om*/ * @param property * @param value * @return */ private static Criterion createNumericalCriterion(Operator operator, String property, NumericValue value) { Criterion criterion; switch (operator) { case NUMERIC_GREATER: criterion = Restrictions.gt(property, value.getValue()); break; case NUMERIC_LESS: criterion = Restrictions.lt(property, value.getValue()); break; case NUMERIC_EQUAL: criterion = Restrictions.eq(property, value.getValue()); break; case NUMERIC_NOT_EQUAL: criterion = Restrictions.ne(property, value.getValue()); break; default: throw new IllegalArgumentException(); } return criterion; }
From source file:uk.ac.ox.oucs.vle.CourseDAOImpl.java
License:Educational Community License
public List<CourseComponentDAO> findCourseComponents(final String courseId, final Range range, final Date now) { return (List<CourseComponentDAO>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(CourseComponentDAO.class); Criteria subCriteria;// w w w.java 2s.c om switch (range) { case NOTSTARTED: case UPCOMING: criteria.add(Restrictions.or(Restrictions.gt("baseDate", now), Restrictions .and(Restrictions.isNull("baseDate"), Restrictions.isNotNull("startsText")))); break; case PREVIOUS: Date startLastYear = getPreviousYearBeginning(new LocalDate(now)).toDate(); criteria.add(Restrictions.or( Restrictions.and(Restrictions.le("baseDate", now), Restrictions.gt("baseDate", startLastYear)), Restrictions.and(Expression.isNull("baseDate"), Restrictions.isNull("startsText")))); break; } subCriteria = criteria.createCriteria("groups", JoinFragment.INNER_JOIN); subCriteria.add(Restrictions.eq("courseId", courseId)); subCriteria.add(Restrictions.eq("hideGroup", false)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); } }); }
From source file:uk.ac.sussex.model.base.RestrictionList.java
License:Open Source License
/** * Attribute must be greater than integer value. * @param attributeName/*from ww w . ja va 2 s . co m*/ * @param value */ public void addGTDouble(String attributeName, Double value) { this.add(Restrictions.gt(attributeName, value)); }
From source file:uk.ac.sussex.model.base.RestrictionList.java
License:Open Source License
public void addGTInt(String attributeName, Integer value) { this.add(Restrictions.gt(attributeName, value)); }
From source file:uk.org.rbc1b.roms.db.application.HibernateUserDao.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<User> findAllUsers() { Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(User.class); criteria.add(Restrictions.gt("personId", 0)); return criteria.list(); }
From source file:unique.Consultas.ConsultaNiveis.java
private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed // TODO add your handling code here: int x = tblNiveis.getRowCount(); DefaultTableModel model = (DefaultTableModel) tblNiveis.getModel(); for (int i = 0; i < x; i++) { model.removeRow(0);//from ww w.java 2s . com } try { conexao = HibernateUtil.openSession(); Criteria crit = conexao.createCriteria(Nivel.class); if (!txtCodigo.getText().isEmpty()) crit.add(Restrictions.eq("Codigo", txtCodigo.getText())); if (!txtNome.getText().isEmpty()) crit.add(Restrictions.eq("Nome", txtNome.getText())); String temp = txtValorAulas.getText(); temp = temp.replaceAll("\\.", ""); temp = temp.replaceAll("\\,", "."); Double valor = Double.parseDouble(temp); if (valor > 0) { switch (comboAulas.getSelectedIndex()) { case 0: crit.add(Restrictions.lt("ValorAulas", valor)); //less than case 1: crit.add(Restrictions.eq("ValorAulas", valor)); //equals case 2: crit.add(Restrictions.gt("ValorAulas", valor)); //greater than } } temp = txtValorMaterial.getText(); temp = temp.replaceAll("\\.", ""); temp = temp.replaceAll("\\,", "."); valor = Double.parseDouble(temp); if (valor > 0) { switch (comboMaterial.getSelectedIndex()) { case 0: crit.add(Restrictions.lt("ValorMaterial", valor)); //less than case 1: crit.add(Restrictions.eq("ValorMaterial", valor)); //equals case 2: crit.add(Restrictions.gt("ValorMaterial", valor)); //greater than } } crit.addOrder(Order.asc("Codigo")); List<Nivel> results = crit.list(); String codigo, nome, descricao, valorAulas, valorMaterial, duracao; for (Nivel n : results) { if (n.getCodigo() == null) codigo = " "; else codigo = n.getCodigo(); if (n.getNome() == null) nome = " "; else nome = n.getNome(); if (n.getDescricao() == null) descricao = " "; else descricao = n.getDescricao(); if (n.getValorAulas() == null) valorAulas = "0.000,00"; else valorAulas = n.getValorAulas().toString(); if (n.getValorMaterial() == null) valorMaterial = "0.000,00"; else valorMaterial = n.getValorMaterial().toString(); if (n.getDuracao() == null) duracao = "0"; else duracao = n.getDuracao().toString(); String vip = "No"; if (n.isVIP()) vip = "Sim"; String[] linha = new String[] { n.getID().toString(), codigo, nome, descricao, valorAulas, valorMaterial, duracao, vip }; model.addRow(linha); } conexao.close(); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Operao mal sucedida. Motivo: " + e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } resizeColumnWidth(tblNiveis); }