List of usage examples for org.hibernate Query iterate
Iterator<R> iterate();
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public List getIssueNameMap(String issueKey) throws ServiceLocatorException { List issueMap = new ArrayList(); if (CacheManager.getCache().containsKey(issueKey)) { issueMap = (List) CacheManager.getCache().get(issueKey); //returning sigleton object. } else {//from ww w . j a v a 2 s. co m //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 IssueNameData 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. issueMap.add(desc); } // closing for loop. CacheManager.getCache().put(issueKey, issueMap); try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } } } } // closing if condition. return issueMap; // returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public List getEmployeesMap(String employeeKey) throws ServiceLocatorException { List empMap = new ArrayList(); if (CacheManager.getCache().containsKey(employeeKey)) { empMap = (List) CacheManager.getCache().get(employeeKey); //returning sigleton object. } else {//from w w w . j a va 2 s . co m //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 EmployData 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. empMap.add(desc); } // closing for loop. CacheManager.getCache().put(employeeKey, empMap); try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } } } } // closing if condition. return empMap; // returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public int getAccountIdByMapId(int inProjectId) throws ServiceLocatorException { int accountId = 0; Object accountIdObject = null; Session session = HibernateServiceLocator.getInstance().getSession(); Transaction transaction = session.beginTransaction(); String SQL_QUERY = "Select tp.accountId from MapDataForAccountId as tp where tp.id=:inProjectId"; Query query = session.createQuery(SQL_QUERY).setInteger("inProjectId", inProjectId); for (Iterator it = query.iterate(); it.hasNext();) { accountIdObject = (Object) it.next(); } //end of the for loop if (accountIdObject == null) accountIdObject = "0"; accountId = Integer.parseInt(accountIdObject.toString()); try {//from w w w. j a v a 2s . c o m // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } } } return accountId; }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public int getAccountIdByIssueId(int inIssueId) throws ServiceLocatorException { int accountId = 0; Object accountIdObject = null; Session session = HibernateServiceLocator.getInstance().getSession(); Transaction transaction = session.beginTransaction(); String SQL_QUERY = "Select tp.accountId from IssueDataForAccountId as tp where tp.id=:inIssueId"; Query query = session.createQuery(SQL_QUERY).setInteger("inIssueId", inIssueId); for (Iterator it = query.iterate(); it.hasNext();) { accountIdObject = (Object) it.next(); } //end of the for loop if (accountIdObject == null) accountIdObject = "0"; accountId = Integer.parseInt(accountIdObject.toString()); try {//from w w w . j ava 2 s .c om // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { he.printStackTrace(); } } } return accountId; }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public List getCrmActivityTypesAll(String crmAllActivityTypeKey) throws ServiceLocatorException { // System.out.println("edit"); List crmActivityTypesList = new ArrayList();//Description if (CacheManager.getCache().containsKey(crmAllActivityTypeKey)) { crmActivityTypesList = (List) CacheManager.getCache().get(crmAllActivityTypeKey); } else {//from w w w. ja va2s .com //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 CrmActivityData as tp"; //newly added on 03282013 String SQL_STG = "select tp.description from CrmActivityData 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. crmActivityTypesList.add(desc); } // closing for loop. //Sorting Elements // System.out.println("crmActivityTypesList"+crmActivityTypesList.size()); Collections.sort(crmActivityTypesList); CacheManager.getCache().put(crmAllActivityTypeKey, crmActivityTypesList); 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 crmActivityTypesList;// returning the object. }
From source file:com.mysema.query.jpa.hibernate.AbstractHibernateQuery.java
License:Apache License
/** * Return the query results as an <tt>Iterator</tt>. If the query * contains multiple results pre row, the results are returned in * an instance of <tt>Object[]</tt>.<br> * <br>/* w w w . ja v a2 s .com*/ * Entities returned as results are initialized on demand. The first * SQL query returns identifiers only.<br> */ @SuppressWarnings("unchecked") public CloseableIterator<Object[]> iterate(Expression<?>[] args) { Query query = createQuery(args); reset(); return new IteratorAdapter<Object[]>(query.iterate()); }
From source file:com.mysema.query.jpa.hibernate.AbstractHibernateQuery.java
License:Apache License
/** * Return the query results as an <tt>Iterator</tt>. If the query * contains multiple results pre row, the results are returned in * an instance of <tt>Object[]</tt>.<br> * <br>//from w ww . ja v a2 s . c om * Entities returned as results are initialized on demand. The first * SQL query returns identifiers only.<br> */ @SuppressWarnings("unchecked") public <RT> CloseableIterator<RT> iterate(Expression<RT> projection) { Query query = createQuery(projection); reset(); return new IteratorAdapter<RT>(query.iterate()); }
From source file:com.openkm.dao.NodeDocumentDAO.java
License:Open Source License
/** * Check if text has been already extracted. *//*from w w w . j av a 2s . com*/ public boolean isTextExtracted(String uuid) throws DatabaseException { log.debug("isTextExtracted()"); String qs = "from NodeDocument nd where nd.uuid=:uuid and nd.textExtracted=:extracted"; Session session = null; Transaction tx = null; boolean ret = false; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setString("uuid", uuid); q.setBoolean("extracted", true); ret = q.iterate().hasNext(); HibernateUtil.commit(tx); log.debug("isTextExtracted: {}", ret); return ret; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.module.db.DbDashboardModule.java
License:Open Source License
/** * Get top documents/* w w w. j a v a2 s . com*/ */ @SuppressWarnings("unchecked") private ArrayList<DashboardDocumentResult> getTopDocuments(String user, String source, String qs, Calendar date) throws RepositoryException, DatabaseException { log.debug("getTopDocuments({}, {}, {}, {})", new Object[] { user, source, qs, (date != null ? date.getTime() : "null") }); ArrayList<DashboardDocumentResult> al = new ArrayList<DashboardDocumentResult>(); Cache docResultCache = CacheProvider.getInstance().getCache(CACHE_DASHBOARD_TOP_DOCUMENTS); String key = source + ":" + Config.SYSTEM_USER; Element elto = docResultCache.get(key); if (elto != null) { log.debug("Get '{}' from cache", source); al = (ArrayList<DashboardDocumentResult>) elto.getValue(); } else { log.debug("Get '{}' from database", source); Session session = null; int cont = 0; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs).setFetchSize(MAX_RESULTS); if (date != null) { q.setCalendar("date", date); } // While there is more query results and the MAX_RESULT limit has reached for (Iterator<Object[]> it = q.iterate(); it.hasNext() && cont < MAX_RESULTS; cont++) { Object[] obj = it.next(); String resItem = (String) obj[0]; Calendar resDate = (Calendar) obj[1]; try { NodeDocument nDoc = NodeDocumentDAO.getInstance().findByPk(resItem); // String docPath = NodeBaseDAO.getInstance().getPathFromUuid(nDoc.getUuid()); // Only documents from taxonomy // Already filtered in the query // if (docPath.startsWith("/okm:root")) { Document doc = BaseDocumentModule.getProperties(user, nDoc); DashboardDocumentResult vo = new DashboardDocumentResult(); vo.setDocument(doc); vo.setDate(resDate); vo.setVisited(false); al.add(vo); // } } catch (PathNotFoundException e) { // Do nothing } } docResultCache.put(new Element(key, al)); } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } } log.debug("getTopDocuments: {}", al); return al; }
From source file:com.sap.data.db.dao.StructureDao.java
public int countSize() throws NotFoundException { int querySize = 0; Session session = null;/*from ww w . j a va 2 s . c o m*/ try { session = HibernateUtil.getSession(); session.setCacheMode(CacheMode.GET); Query query = session.createQuery("select count(o) from " + this.structure + " o"); querySize = ((Long) query.iterate().next()).intValue(); } catch (HibernateException | IllegalArgumentException ex) { Logger.getLogger(StructureDao.class.getName()).log(Level.SEVERE, null, ex); throw new NotFoundException(ex.getMessage()); } finally { HibernateUtil.close(session); } return querySize; }