List of usage examples for org.hibernate Query setParameter
@SuppressWarnings("unchecked") Query<R> setParameter(int position, Object val);
From source file:at.thinkingco2.databasemanager.CarAccess.java
/** * This function returns a CarBean specified by its LicenseNumber * /*from w ww . jav a 2 s . c o m*/ * @param licenseNumber * the LicenseNumber of the searched Car * @return the CarBean */ public CarBean getCarByLicenseNumber(String licenseNumber) { Session session = getSession(); CarBean bean = null; Query q = null; q = session.createQuery("FROM CarBean WHERE licenseNumber = :licenseNumber"); q.setParameter("licenseNumber", licenseNumber); bean = (CarBean) q.uniqueResult(); session.close(); return bean; }
From source file:at.thinkingco2.databasemanager.JourneyAccess.java
/** * This function returns the Number of used Seats in a given Route * //from w ww. j a v a2s . com * @param routeId * The routeId * @return Number of used Seats */ @SuppressWarnings("unchecked") public Integer getUsedSeats(Integer routeId) { Session session = getSession(); List<JourneyBean> journeyList = null; Integer seats = 0; Query q = null; q = session.createQuery("FROM JourneyBean WHERE routeId = :routeId"); q.setParameter("routeId", routeId); journeyList = q.list(); for (JourneyBean journey : journeyList) { seats += journey.getChildren().size(); } session.close(); return seats + 1; // +1 = + parent }
From source file:at.thinkingco2.databasemanager.JourneyAccess.java
@SuppressWarnings("unchecked") public List<JourneyBean> getJourneysByRouteID(Integer routeId) { Session session = getSession();/* w ww. ja va 2 s. co m*/ List<JourneyBean> list = null; Query q = session.createQuery("FROM JourneyBean WHERE routeId = :routeId"); q.setParameter("routeId", routeId); list = q.list(); session.close(); return list; }
From source file:at.thinkingco2.databasemanager.JourneyAccess.java
public JourneyBean getJourney(int id) { Session session = getSession();/*from w ww.j a v a2 s . c om*/ Query q = session.createQuery("FROM JourneyBean WHERE journeyId = :id"); q.setParameter("id", id); JourneyBean res = (JourneyBean) q.uniqueResult(); session.close(); return res; }
From source file:at.thinkingco2.databasemanager.JourneyAccess.java
public JourneyBean getJourney(JourneyBean journeyBean) { Session session = getSession();//from www. jav a2 s .co m Query q = session .createQuery("FROM JourneyBean WHERE description = :description AND arrivleTime = :arrivleTime"); q.setParameter("description", journeyBean.getDescription()); q.setParameter("arrivleTime", journeyBean.getArrivleTime()); JourneyBean res = (JourneyBean) q.uniqueResult(); session.close(); return res; }
From source file:at.treedb.db.hibernate.DAOhibernate.java
License:Open Source License
@Override public List<?> query(String query, HashMap<String, Object> map) { Query q; if (isStatelessSession) { q = statelessSession.createQuery(query); } else {/*from w w w. j a v a 2s . com*/ q = session.createQuery(query); } if (map != null) { Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); Object o = map.get(key); q.setParameter(key, o); } } return q.list(); }
From source file:at.treedb.db.hibernate.DAOhibernate.java
License:Open Source License
/** * Creates a Hibernate query object.//w ww. j av a 2 s .c om * * @param query * query string * @param map * query parameter * @return Hibernate query object */ public Query createQuery(String query, HashMap<String, Object> map) { Query q; if (isStatelessSession) { q = statelessSession.createQuery(query); } else { q = session.createQuery(query); } if (map != null) { Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); Object o = map.get(key); q.setParameter(key, o); } } return q; }
From source file:at.treedb.db.hibernate.DAOhibernate.java
License:Open Source License
@Override public int queryAndExecute(String query, HashMap<String, Object> map) { Query q; if (isStatelessSession) { q = statelessSession.createQuery(query); } else {//from www. j a va 2 s . c o m q = session.createQuery(query); } if (map != null) { Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); Object o = map.get(key); q.setParameter(key, o); } } return q.executeUpdate(); }
From source file:at.treedb.db.hibernate.DAOhibernate.java
License:Open Source License
@Override public List<?> query(String query, int start, int length, HashMap<String, Object> map) { Query q; if (isStatelessSession) { q = statelessSession.createQuery(query); } else {/*from ww w . j a v a 2 s .c o m*/ q = session.createQuery(query); } if (map != null) { Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); Object o = map.get(key); q.setParameter(key, o); } } q.setFirstResult(start); q.setMaxResults(length); return q.list(); }
From source file:au.com.nicta.ct.experiment.coordinates.CtCoordinatesModel.java
License:Open Source License
public void createImages() { _cachedImages.clear();/* www . ja va 2 s . c om*/ HashSet<CtImages> completed = new HashSet<CtImages>(); Session s = CtSession.Current(); s.beginTransaction(); String hql = "FROM CtImages i " + "INNER JOIN FETCH i.ctImagesCoordinateses ic " + "INNER JOIN FETCH ic.ctCoordinates c " // put into hibernate cache, ie i obj should be complete + "INNER JOIN FETCH c.ctCoordinatesTypes ct " + "WHERE i.ctExperiments = :experiment " + "ORDER BY i, ct"; Query q = s.createQuery(hql); q.setParameter("experiment", _am._e); List<Object[]> l = (List<Object[]>) q.list(); // all data should be accessed once, here. Iterator i = l.iterator(); while (i.hasNext()) { CtImages image = (CtImages) i.next(); // Object[] os = (Object[])i.next(); // // CtImages image = (CtImages)os[ 0 ]; if (completed.contains(image)) { continue; // already loaded this one. } ArrayList<CtAbstractPair<String, Integer>> al = new ArrayList<CtAbstractPair<String, Integer>>(); // hibernate should've loaded the fetches objects, so: // CtImages image = (CtImages) os[ 0 ]; // CtImagesCoordinates ic = (CtImagesCoordinates)os[ 1 ]; // CtCoordinates c = (CtCoordinates) os[ 2 ]; // CtCoordinatesTypes ct = (CtCoordinatesTypes) os[ 3 ]; // each image has multiple coordinates/types. build a list of them all. Set<CtImagesCoordinates> sic = image.getCtImagesCoordinateses(); // TODO: Check this is auto preloaded and not generating further DB hits.. for (CtImagesCoordinates ic : sic) { CtCoordinates c = ic.getCtCoordinates(); CtCoordinatesTypes ct = c.getCtCoordinatesTypes(); CtAbstractPair<String, Integer> ap = new CtAbstractPair<String, Integer>(); ap._first = ct.getName(); ap._second = c.getValue(); al.add(ap); } String key = getImageKey(al); _cachedImages.put(key, image); completed.add(image); } s.getTransaction().commit(); }