List of usage examples for org.hibernate.criterion Restrictions between
public static Criterion between(String propertyName, Object low, Object high)
From source file:eu.cloud4soa.relational.persistence.SLAViolationRepository.java
License:Apache License
/** * Returns all SLA violations for a given User between two moments in time. * /*from w w w . j a v a 2 s .co m*/ * @param userId the user id * @param start the moment we start to get the SLA violations * @param end the moment we finish to get the SLA violations * @return a list of SLA violations */ public List<SLAViolation> retrieveAllForUserAndTime(String userId, Date start, Date end) { DetachedCriteria user_criteria = DetachedCriteria.forClass(User.class).add(Restrictions.eq("uriID", userId)) .setProjection(Projections.property("id")); DetachedCriteria acc_criteria = DetachedCriteria.forClass(Account.class) .add(Property.forName("user.id").in(user_criteria)).setProjection(Projections.property("id")); DetachedCriteria app_criteria = DetachedCriteria.forClass(ApplicationInstance.class) .add(Property.forName("account.id").in(acc_criteria)).setProjection(Projections.property("uriID")); return (List<SLAViolation>) getSession().createCriteria(SLAViolation.class) .add(Property.forName("applicationInstanceUriId").in(app_criteria)) .add(Restrictions.between("dateAndTime", start, end)).list(); }
From source file:eu.ist_phosphorus.harmony.idb.database.hibernate.Reservation.java
License:Open Source License
/** * load all reservations from DB which lie in a given time-period. *//*from ww w .jav a2s . c o m*/ @SuppressWarnings("unchecked") public static final Set<Reservation> loadAllInPeriod(Date startTime, Date endTime) throws DatabaseException { return (Set<Reservation>) (new TransactionManager(new Tuple<Date, Date>(startTime, endTime)) { @Override protected void dbOperation() { Set<Reservation> result = new HashSet<Reservation>(); Tuple<Date, Date> times = (Tuple<Date, Date>) this.arg; // select all reservation-IDs from ReservationPeriod-view, which // lie in the given time-period DetachedCriteria ids = DetachedCriteria.forClass(VIEW_ReservationPeriod.class) .setProjection(Property.forName("reservationId")) .add(Restrictions.disjunction() .add(Restrictions.between("startTime", times.getFirstElement(), times.getSecondElement())) .add(Restrictions.between("endTime", times.getFirstElement(), times.getSecondElement())) .add(Restrictions.and(Restrictions.le("startTime", times.getFirstElement()), Restrictions.ge("endTime", times.getSecondElement())))); // select all reservations from DB accoring to the IDs from step // one final List<Reservation> tmpReservation = this.session.createCriteria(Reservation.class) .add(Subqueries.propertyIn("reservationId", ids)) // use join-select, because all infos will be // needed later .setFetchMode("Reservation", FetchMode.JOIN).list(); for (Reservation r : tmpReservation) { result.add(r); } this.result = result; } }).getResult(); }
From source file:eu.optimis.ecoefficiencytool.trecdb.ip.EcoIpTableDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public static List<EcoValue> getEcoAssessments(String ini, String end, String metric) throws Exception { List<EcoValue> assessments = new LinkedList<EcoValue>(); Session session = null;//from w w w .java2 s .com List<IpEcoIpTable> results = null; SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); // Obtain ecoAssessments in a range of time. Criteria criteria = session.createCriteria(IpEcoIpTable.class); Date startDate = DateFormatter.getDateFromString(ini); Date endDate = DateFormatter.getDateFromString(end); //criteria.add(Expression.between("timestamp", new Date(startDate.getTime()), new Date(endDate.getTime()))); criteria.add(Restrictions.between("timestamp", startDate, endDate)); results = (List<IpEcoIpTable>) criteria.list(); tx.commit(); } catch (Exception e) { log.error("Error while obtaining assessments: " + e.getMessage()); throw new Exception(e.toString()); } if ("ecological".equalsIgnoreCase(metric)) { for (IpEcoIpTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEcologicalEffIp()))); } } else if ("energy".equalsIgnoreCase(metric)) { for (IpEcoIpTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEnergyEffIp()))); } } else if ("performance".equalsIgnoreCase(metric)) { for (IpEcoIpTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getPerformanceIp()))); } } else if ("power".equalsIgnoreCase(metric)) { for (IpEcoIpTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getPowerIp()))); } } else if ("co2".equalsIgnoreCase(metric)) { for (IpEcoIpTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getGrCo2sIp()))); } } return assessments; }
From source file:eu.optimis.ecoefficiencytool.trecdb.ip.EcoNodeTableDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public static List<EcoValue> getEcoAssessments(String nodeId, String ini, String end, String metric) throws Exception { List<EcoValue> assessments = new LinkedList<EcoValue>(); Session session = null;//from w ww. j av a 2 s . co m List<IpEcoNodeTable> results = null; SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); // Obtain ecoAssessments in a range of time. Criteria criteria = session.createCriteria(IpEcoNodeTable.class); Date startDate = DateFormatter.getDateFromString(ini); Date endDate = DateFormatter.getDateFromString(end); //criteria.add(Expression.between("timestamp", new Date(startDate.getTime()), new Date(endDate.getTime()))); criteria.add(Restrictions.like("nodeId", nodeId)); criteria.add(Restrictions.between("timestamp", startDate, endDate)); results = (List<IpEcoNodeTable>) criteria.list(); tx.commit(); } catch (Exception e) { log.error("Error while obtaining node " + nodeId + " assessments: " + e.getMessage()); throw new Exception(e.toString()); } if ("ecological".equalsIgnoreCase(metric)) { for (IpEcoNodeTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEcologicalEffNode()))); } } else if ("energy".equalsIgnoreCase(metric)) { for (IpEcoNodeTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEnergyEffNode()))); } } else if ("performance".equalsIgnoreCase(metric)) { for (IpEcoNodeTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getPerformanceNode()))); } } else if ("power".equalsIgnoreCase(metric)) { for (IpEcoNodeTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getPowerNode()))); } } else if ("co2".equalsIgnoreCase(metric)) { for (IpEcoNodeTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getGrCo2sNode()))); } } return assessments; }
From source file:eu.optimis.ecoefficiencytool.trecdb.ip.EcoServiceTableDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public static List<EcoValue> getEcoAssessments(String serviceId, String ini, String end, String metric) throws Exception { List<EcoValue> assessments = new LinkedList<EcoValue>(); Session session = null;/* w w w .jav a2 s. c o m*/ List<IpEcoService> results = null; SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); // Obtain ecoAssessments in a range of time. Criteria criteria = session.createCriteria(IpEcoService.class); Date startDate = DateFormatter.getDateFromString(ini); Date endDate = DateFormatter.getDateFromString(end); //criteria.add(Expression.between("timestamp", new Date(startDate.getTime()), new Date(endDate.getTime()))); criteria.add(Restrictions.like("serviceId", serviceId)); criteria.add(Restrictions.between("timestamp", startDate, endDate)); results = (List<IpEcoService>) criteria.list(); tx.commit(); } catch (Exception e) { log.error("Error while obtaining service " + serviceId + " assessments: " + e.getMessage()); throw new Exception(e.toString()); } if ("ecological".equalsIgnoreCase(metric)) { for (IpEcoService table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEcologicalEffService()))); } } else if ("energy".equalsIgnoreCase(metric)) { for (IpEcoService table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEnergyEffService()))); } } else if ("performance".equalsIgnoreCase(metric)) { for (IpEcoService table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getPerformanceService()))); } } else if ("power".equalsIgnoreCase(metric)) { for (IpEcoService table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getPowerService()))); } } else if ("co2".equalsIgnoreCase(metric)) { for (IpEcoService table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getGrCo2sService()))); } } return assessments; }
From source file:eu.optimis.ecoefficiencytool.trecdb.ip.EcoVMTableDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public static List<EcoValue> getEcoAssessments(String vmId, String ini, String end, String metric) throws Exception { List<EcoValue> assessments = new LinkedList<EcoValue>(); Session session = null;/*w w w . j a v a 2 s .co m*/ List<IpEcoVmTable> results = null; SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); // Obtain ecoAssessments in a range of time. Criteria criteria = session.createCriteria(IpEcoVmTable.class); Date startDate = DateFormatter.getDateFromString(ini); Date endDate = DateFormatter.getDateFromString(end); //criteria.add(Expression.between("timestamp", new Date(startDate.getTime()), new Date(endDate.getTime()))); criteria.add(Restrictions.like("vmId", vmId)); criteria.add(Restrictions.between("timestamp", startDate, endDate)); results = (List<IpEcoVmTable>) criteria.list(); tx.commit(); } catch (Exception e) { log.error("Error while obtaining node " + vmId + " assessments: " + e.getMessage()); throw new Exception(e.toString()); } if ("ecological".equalsIgnoreCase(metric)) { for (IpEcoVmTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEcologicalEffVm()))); } } else if ("energy".equalsIgnoreCase(metric)) { for (IpEcoVmTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEnergyEffVm()))); } } else if ("performance".equalsIgnoreCase(metric)) { for (IpEcoVmTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getPerformanceVm()))); } } else if ("power".equalsIgnoreCase(metric)) { for (IpEcoVmTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getPowerVm()))); } } else if ("co2".equalsIgnoreCase(metric)) { for (IpEcoVmTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getGrCo2sVm()))); } } return assessments; }
From source file:eu.optimis.ecoefficiencytool.trecdb.sp.EcoServiceTableDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public static List<EcoValue> getEcoAssessments(String serviceId, String ini, String end, String metric) throws Exception { List<EcoValue> assessments = new LinkedList<EcoValue>(); Session session = null;/*from w w w .jav a 2 s . co m*/ List<SpEcoServiceTable> results = null; SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); // Obtain ecoAssessments in a range of time. Criteria criteria = session.createCriteria(SpEcoServiceTable.class); Date startDate = DateFormatter.getDateFromString(ini); Date endDate = DateFormatter.getDateFromString(end); //criteria.add(Expression.between("timestamp", new Date(startDate.getTime()), new Date(endDate.getTime()))); criteria.add(Restrictions.like("serviceId", serviceId)); criteria.add(Restrictions.between("timestamp", startDate, endDate)); results = (List<SpEcoServiceTable>) criteria.list(); tx.commit(); } catch (Exception e) { log.error("Error while obtaining service " + serviceId + " assessments: ", e); throw new Exception(e.toString()); } if ("ecological".equalsIgnoreCase(metric)) { for (SpEcoServiceTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEcologicalEffService()))); } } else if ("energy".equalsIgnoreCase(metric)) { for (SpEcoServiceTable table : results) { assessments.add(new EcoValue(table.getTimestamp(), new Double(table.getEnergyEffService()))); } } return assessments; }
From source file:financeiro.dao.hibernate.LancamentoDAOHibernate.java
License:Creative Commons License
@SuppressWarnings("unchecked") @Override/*w w w. j ava 2 s . co m*/ public List<Lancamento> listar(Conta conta, Date dataInicio, Date dataFim) { Criteria criteria = this.session.createCriteria(Lancamento.class); if (dataInicio != null && dataFim != null) { criteria.add(Restrictions.between("data", dataInicio, dataFim)); } else if (dataInicio != null) { criteria.add(Restrictions.ge("data", dataInicio)); } else if (dataFim != null) { criteria.add(Restrictions.le("data", dataFim)); } criteria.add(Restrictions.eq("conta", conta)); criteria.addOrder(Order.asc("data")); return criteria.list(); }
From source file:forms.frmEstate.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed Criteria criteria = db.getCriteria(Apartmentsandoffices.class); //ehir/*from ww w .ja v a2 s. c o m*/ if (jComboBox1.getSelectedIndex() > 0) { criteria.add(Restrictions.eq("address", jComboBox1.getSelectedIndex())); } //fiyat if (jTextField1.getText().length() > 0 && jTextField2.getText().length() > 0) { criteria.add(Restrictions.between("price", Integer.valueOf(jTextField1.getText()), Integer.valueOf(jTextField2.getText()))); } else if (jTextField1.getText().length() > 0) { criteria.add(Restrictions.ge("price", Integer.valueOf(jTextField1.getText()))); } else if (jTextField2.getText().length() > 0) { criteria.add(Restrictions.le("price", Integer.valueOf(jTextField2.getText()))); } //oda says if (jComboBox2.getSelectedIndex() > 0) { criteria.add(Restrictions.eq("roomcount", jComboBox2.getSelectedIndex())); } //bina ya if (jComboBox3.getSelectedIndex() > 0) { criteria.add(Restrictions.eq("buildingage", jComboBox3.getSelectedIndex())); } //m2 if (jTextField3.getText().length() > 0 && jTextField9.getText().length() > 0) { criteria.add(Restrictions.between("m2", Integer.valueOf(jTextField3.getText()), Integer.valueOf(jTextField9.getText()))); } else if (jTextField3.getText().length() > 0) { criteria.add(Restrictions.ge("m2", Integer.valueOf(jTextField3.getText()))); } else if (jTextField9.getText().length() > 0) { criteria.add(Restrictions.le("m2", Integer.valueOf(jTextField9.getText()))); } //stma if (jComboBox4.getSelectedIndex() > 0) { criteria.add(Restrictions.eq("heating", jComboBox4.getSelectedIndex())); } //kat if (jComboBox5.getSelectedIndex() > 0) { criteria.add(Restrictions.eq("floor", jComboBox5.getSelectedIndex())); } //toplam kat if (jComboBox6.getSelectedIndex() > 0) { criteria.add(Restrictions.eq("totalfloor", jComboBox6.getSelectedIndex())); } //banyo says if (jTextField4.getText().length() > 0) { criteria.add(Restrictions.eq("bathroomcount", Integer.valueOf(jTextField4.getText()))); } //eyalm if (!jCheckBox1.isSelected() && !jCheckBox2.isSelected()) { //criteria.add(Restrictions.eq("furniture", null)); } else if (jCheckBox1.isSelected()) criteria.add(Restrictions.eq("furniture", true)); else criteria.add(Restrictions.eq("furniture", false)); //emlak tipi if (jComboBox8.getSelectedIndex() > 0) { criteria.add(Restrictions.eq("type", jComboBox8.getSelectedIndex())); } //emlak durumu if (jComboBox7.getSelectedIndex() > 0) { criteria.add(Restrictions.eq("state", jComboBox7.getSelectedIndex())); } apartment.getApartmentAds(criteria.list(), jTable2); }
From source file:forms.frmEstate.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed Criteria criteria = db.getCriteria(Lands.class); if (jComboBox9.getSelectedIndex() > 0) criteria.add(Restrictions.eq("address", jComboBox9.getSelectedIndex())); if (jComboBox25.getSelectedIndex() > 0) criteria.add(Restrictions.eq("state", jComboBox25.getSelectedIndex())); if (jComboBox26.getSelectedIndex() > 0) criteria.add(Restrictions.eq("reconstruction", jComboBox26.getSelectedIndex())); if (jComboBox27.getSelectedIndex() > 0) criteria.add(Restrictions.eq("deedstate", jComboBox27.getSelectedIndex())); if (jComboBox28.getSelectedIndex() > 0) criteria.add(Restrictions.eq("clearance", jComboBox28.getSelectedIndex())); if (jComboBox29.getSelectedIndex() > 0) criteria.add(Restrictions.eq("kaks", jComboBox29.getSelectedIndex())); //fiyat/* w ww . j a va2 s . c o m*/ if (jTextField5.getText().length() > 0 && jTextField6.getText().length() > 0) { criteria.add(Restrictions.between("price", Integer.valueOf(jTextField5.getText()), Integer.valueOf(jTextField6.getText()))); } else if (jTextField5.getText().length() > 0) { criteria.add(Restrictions.ge("price", Integer.valueOf(jTextField5.getText()))); } else if (jTextField6.getText().length() > 0) { criteria.add(Restrictions.le("price", Integer.valueOf(jTextField6.getText()))); } //m2 if (jTextField13.getText().length() > 0 && jTextField14.getText().length() > 0) { criteria.add(Restrictions.between("m2", Integer.valueOf(jTextField13.getText()), Integer.valueOf(jTextField14.getText()))); } else if (jTextField13.getText().length() > 0) { criteria.add(Restrictions.ge("m2", Integer.valueOf(jTextField13.getText()))); } else if (jTextField14.getText().length() > 0) { criteria.add(Restrictions.le("m2", Integer.valueOf(jTextField14.getText()))); } land.getLandAds(criteria.list(), jTable3); }