List of usage examples for org.hibernate Query iterate
Iterator<R> iterate();
From source file:com.mangocity.util.dao.GenericDAOHibernateImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public <T> List<T> query(final String hql, final Object[] paramValues, final int startIndex, final int maxResults, final boolean cacheable) { try {/* w w w. j a v a 2s. c om*/ return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(hql); if (paramValues != null && paramValues.length > 0) { for (int i = 0; i < paramValues.length; i++) { setObjectFromType(paramValues[i], query, i); } } query.setFirstResult(startIndex); if (maxResults > 0) { query.setMaxResults(maxResults); } List resultList = null; if (cacheable) { resultList = ListUtil.itTo(query.iterate()); } else { resultList = query.list(); if (resultList == null) { resultList = Collections.EMPTY_LIST; } } return resultList; } }); } catch (DataAccessException dae) { throw new DAException(DataAccessError.DATA_ACCESS_FAILED, dae); } }
From source file:com.mangocity.util.dao.GenericDAOHibernateImpl.java
License:Open Source License
public List doquery(final String hql, final Object value, final boolean cache) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(hql); setObjectFromType(value, query, 0); if (cache) { return ListUtil.itTo(query.iterate()); } else { return query.list(); }//from www .j av a 2s . c o m } }); }
From source file:com.mangocity.util.dao.GenericDAOHibernateImpl.java
License:Open Source License
public List doquery(final String hql, final Object[] values, final boolean cache) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(hql); List list = null;// ww w . j a v a 2 s . c o m for (int i = 0; null != values && i < values.length; i++) { Object value = values[i]; setObjectFromType(value, query, i); } if (cache) { list = ListUtil.itTo(query.iterate()); session.close(); return list; } else { list = query.list(); session.close(); return list; } } }); }
From source file:com.mss.mirage.crm.attachments.AttachmentServiceImpl.java
License:Open Source License
public String getAttachmentLocation(int attachmentId) throws ServiceLocatorException { Session session = HibernateServiceLocator.getInstance().getSession(); Transaction transaction = session.beginTransaction(); String attachmentLocation = null; String SQL_QUERY = "Select h.attachmentLocation from AttachmentAction as h where h.id=:attachmentId"; Query query = session.createQuery(SQL_QUERY).setInteger("attachmentId", attachmentId); for (Iterator it = query.iterate(); it.hasNext();) { attachmentLocation = (String) it.next(); } //end of the for loop if (session != null) { try {//w ww. ja v a 2 s . c o m session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } } return attachmentLocation; }
From source file:com.mss.mirage.projects.ProjectServiceImpl.java
License:Open Source License
public String getPath(int attachmentId) throws ServiceLocatorException { String Path = null;//from www.j a va 2 s . co m Session session = HibernateServiceLocator.getInstance().getSession(); Transaction transaction = session.beginTransaction(); String SQL_QUERY = "Select h.Path from DownloadAction as h where h.id=:attachmentId"; Query query = session.createQuery(SQL_QUERY).setInteger("attachmentId", attachmentId); for (Iterator it = query.iterate(); it.hasNext();) { Path = (String) it.next(); } //end of the for loop if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } return Path; }
From source file:com.mss.mirage.recruitment.attachments.ConsultantAttachmentServiceImpl.java
License:Open Source License
/** * This method can be use to download a attachment file of the consultant. * *@throws ServiceLocatorException//from w w w. ja v a2s. c o m * If a ServiceLocatorException exists and its <code>{ *@link com.mss.mirage.util.ServiceLocatorException * }</code> * @param attachmentId. * @return String attachmentLocation - its returns attachmentLocation when consultant attachment attachment file downloaded successfully . */ public String getAttachmentLocation(int attachmentId) throws ServiceLocatorException { String attachmentLocation = ""; Session session = HibernateServiceLocator.getInstance().getSession(); Transaction transaction = session.beginTransaction(); String SQL_QUERY = "Select h.filepath from ConsultantAttachmentAction as h where h.id=:attachmentId"; Query query = session.createQuery(SQL_QUERY).setInteger("attachmentId", attachmentId); for (Iterator it = query.iterate(); it.hasNext();) { attachmentLocation = (String) it.next(); } //end of the for loop try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } } return attachmentLocation; }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public List getProjectAttachType(String projectAttachTypeKey) throws ServiceLocatorException { List projectAttachTypeList = new ArrayList();//Description if (CacheManager.getCache().containsKey(projectAttachTypeKey)) { projectAttachTypeList = (List) CacheManager.getCache().get(projectAttachTypeKey); } else {// ww w .ja v a2 s . co m //getting sessionFactory for the HibernateUtil class. Session session = HibernateServiceLocator.getInstance().getSession(); //Creating a transaction for the session object. Transaction tran = session.beginTransaction(); //Genarating a quary for retrieving the data from the database. String SQL_STG = "select tp.description from ProjectAttachTypeData as tp"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { String desc = (String) it.next(); //Storing values into the TreeList. projectAttachTypeList.add(desc); } // closing for loop. CacheManager.getCache().put(projectAttachTypeKey, projectAttachTypeList); try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } } } // closing if condition. return projectAttachTypeList;// returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
/** *@ returns map for Campaigns.//from ww w . ja v a2s . co m *@ throws HibernateException. */ public Map getCampaignNames(String campaignKey) throws ServiceLocatorException { Map campaignsMap = new TreeMap();//key-Description if (CacheManager.getCache().containsKey(campaignKey)) { campaignsMap = (Map) CacheManager.getCache().get(campaignKey); } else { //getting sessionFactory for the HibernateUtil class. Session session = HibernateServiceLocator.getInstance().getSession(); //Creating a transaction for the session object. Transaction tran = session.beginTransaction(); //Genarating a quary for retrieving the data from the database. String SQL_STG = "select tp.id,tp.description from CampaignNamesData as tp"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { Object[] row = (Object[]) it.next(); //Storing values into the TreeMap. campaignsMap.put(row[0].toString(), row[1].toString()); } // closing for loop. //Storing the rolesMap object in to the cache as singleton object. CacheManager.getCache().put(campaignKey, campaignsMap); // Closing hibernate session try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } } } } // closing if condition. return campaignsMap; // returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
/** *@ returns map for Roles.//from w w w . ja v a 2 s . co m *@ throws HibernateException. */ public Map getRoles(String rolesKey) throws ServiceLocatorException { Map rolesMap = new TreeMap();//key-Description if (CacheManager.getCache().containsKey(rolesKey)) { rolesMap = (Map) CacheManager.getCache().get(rolesKey); } else { //getting sessionFactory for the HibernateUtil class. Session session = HibernateServiceLocator.getInstance().getSession(); //Creating a transaction for the session object. Transaction tran = session.beginTransaction(); //Genarating a quary for retrieving the data from the database. // String SQL_STG="select tp.id,tp.description from RolesData as tp WHERE tp.description!='Pre-Sales' AND tp.description!='Sourcing'"; String SQL_STG = "select tp.id,tp.description from RolesData as tp WHERE tp.description!='Pre-Sales' AND tp.description!='Sourcing' AND tp.description!='Recruitment Admin'"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { Object[] row = (Object[]) it.next(); //Storing values into the TreeMap. rolesMap.put(row[0].toString(), row[1].toString()); } // closing for loop. //Storing the rolesMap object in to the cache as singleton object. CacheManager.getCache().put(rolesKey, rolesMap); // Closing hibernate session try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } } } } // closing if condition. return rolesMap; // returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
/** *@ returns List for Countries./*from ww w. j ava2 s . c o m*/ *@ throws HibernateException. */ public List getContries(String countriesKey) throws ServiceLocatorException { List countryList = new ArrayList();//Description if (CacheManager.getCache().containsKey(countriesKey)) { countryList = (List) CacheManager.getCache().get(countriesKey); //returning sigleton object. } else { //getting hibernate session from the HibernateServiceLocator class. Session session = HibernateServiceLocator.getInstance().getSession(); //Creating a transaction for the session object. Transaction tran = session.beginTransaction(); //Genarating a quary for retrieving the data from the database. String SQL_STG = "select tp.description from CountryData as tp"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { String desc = (String) it.next(); //Storing values into the TreeList. countryList.add(desc); } // closing for loop. CacheManager.getCache().put(countriesKey, countryList); try { // Closing hibernate session session.close(); session = null; query = null; } catch (HibernateException he) { he.printStackTrace(); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } } } // closing if condition. return countryList; // returning the object. }