List of usage examples for org.hibernate Query iterate
Iterator<R> iterate();
From source file:de.innovationgate.webgate.api.jdbc.WGDocumentImpl.java
License:Open Source License
/** * @return/*from w ww . j a va 2s . co m*/ */ private int getRevision() throws WGAPIException { try { Session session = _parent.getSession(); String queryString = "select count(*) from LogEntry where target=:target "; Query query = session.createQuery(queryString); query.setParameter("target", _document.getDocumentKey()); return ((Number) query.iterate().next()).intValue(); } catch (HibernateException e) { WGFactory.getLogger() .error("Error retrieving log entries for document '" + _document.getDocumentKey() + "'", e); return 0; } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.exporter.EObjectCreatorImpl.java
License:Open Source License
@SuppressWarnings("unchecked") private Map<EObject, Object> createInstancesForEClass(EClass eClassifier, Session session) { Map<EObject, Object> result = Maps.newLinkedHashMap(); String name = eClassifier.getName(); boolean canBeExported = !(eClassifier.isAbstract() || Iteraplan2EMFHelper.CLASS_NAME.equals(name) || "RuntimePeriod".equals(name)); if (canBeExported) { final Query query = session.createQuery("select xx from " + name + " xx"); Iterator<Object> iterator = query.iterate(); while (iterator.hasNext()) { Object instance = iterator.next(); EObject eObject = createEObject(eClassifier, instance); result.put(eObject, instance); objectToEObject.put(instance, eObject); }//from w ww . j a va 2s. c o m } return result; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.exporter.XmiServiceForTabReporting.java
License:Open Source License
@SuppressWarnings("unchecked") private EObject exportAll(TabReportingEcoreData tabEcoreData) { List<BuildingBlock> buildingBlocks = Lists.newArrayList(); EPackage model = tabEcoreData.getModelPackage(); Session session = sessionFactory.getCurrentSession(); for (EClassifier ec : model.getEClassifiers()) { if (ec instanceof EClass) { EClass eClass = (EClass) ec; String name = eClass.getName(); if (!eClass.isAbstract() && !RUNTIME_PERIOD.equals(name) && !Iteraplan2EMFHelper.CLASS_NAME_TABULARREPORTING.equals(name)) { Query query = session.createQuery("select xx from " + name + " xx"); Iterator<Object> iterator = query.iterate(); while (iterator.hasNext()) { Object entity = iterator.next(); if (entity instanceof BuildingBlock) { buildingBlocks.add((BuildingBlock) entity); } else { LOGGER.error(entity.getClass().getName()); }/*from www .ja va 2s . c o m*/ } } else { LOGGER.debug("Ignored " + name); } } } return export(buildingBlocks, tabEcoreData); }
From source file:de.powerstaff.business.dao.hibernate.FreelancerDAOHibernateImpl.java
License:Open Source License
public List<String> getCodeSuggestions(final String aSuggest) { return (List<String>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session aSession) throws SQLException { List<String> theResult = new Vector<String>(); Query theQuery = aSession.createQuery("select item.code from Freelancer item where item.code like '" + aSuggest.trim() + "%') order by item.code"); for (Iterator theIterator = theQuery.iterate(); theIterator.hasNext();) { String theCode = (String) theIterator.next(); if (!theResult.contains(theCode)) { theResult.add(theCode); }//from w w w. j av a2s . co m } return theResult; } }); }
From source file:de.powerstaff.business.dao.hibernate.FreelancerDAOHibernateImpl.java
License:Open Source License
public Freelancer findByCodeReal(final String aCode) { return (Freelancer) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session aSession) { Query theQuery = aSession.createQuery("from Freelancer item where item.code = :code"); theQuery.setString("code", aCode); for (Iterator theIt = theQuery.iterate(); theIt.hasNext();) { return theIt.next(); }//from ww w . ja v a 2s. com return null; } }); }
From source file:de.powerstaff.business.dao.hibernate.FreelancerDAOHibernateImpl.java
License:Open Source License
private List<Freelancer> internalFindFreelancerByTagIDs(final Set<Long> aTagIDs, final String aSortByFieldName, final boolean aInverse) { final StringBuilder theTagInClause = new StringBuilder(); for (Long theTagID : aTagIDs) { if (theTagInClause.length() > 0) { theTagInClause.append(","); }/*from www.j av a 2s . c o m*/ theTagInClause.append(theTagID); } return (List<Freelancer>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session aSession) throws SQLException { List<Freelancer> theResult = new ArrayList<Freelancer>(); Query theQuery; if (aInverse) { theQuery = aSession.createQuery( "select distinct f from Freelancer f left join f.tags t where t.tag.id in ( " + theTagInClause.toString() + ") order by f." + aSortByFieldName + " desc"); } else { theQuery = aSession.createQuery( "select distinct f from Freelancer f left join f.tags t where t.tag.id in ( " + theTagInClause.toString() + ") order by f." + aSortByFieldName); } for (Iterator theIterator = theQuery.iterate(); theIterator.hasNext();) { Freelancer theFreelancer = (Freelancer) theIterator.next(); if (theFreelancer.hasAllTags(aTagIDs)) { theResult.add(theFreelancer); } } return theResult; } }); }
From source file:de.powerstaff.business.dao.hibernate.NavigatingDAOHibernateImpl.java
License:Open Source License
public T findByRecordNumber(final Long aNumber) { if (aNumber == null) { return findFirst(); }/* w w w .ja v a 2 s . c om*/ return (T) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session aSession) { Query theQuery = aSession.createQuery("from " + getEntityClass().getName() + " order by id"); theQuery.setFirstResult(aNumber.intValue() - 1); theQuery.setMaxResults(1); Iterator theIt = theQuery.iterate(); if (theIt.hasNext()) { return theIt.next(); } return findFirst(); } }); }
From source file:diagrama_bd.base_de_datos.AdministradorDAO.java
public static java.util.Iterator iterateAdministradorByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From diagrama_bd.base_de_datos.Administrador as Administrador"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/* w ww . j a v a 2 s . c o m*/ Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:diagrama_bd.base_de_datos.AdministradorDAO.java
public static java.util.Iterator iterateAdministradorByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From diagrama_bd.base_de_datos.Administrador as Administrador"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {//w w w . j a va2 s .co m Query query = session.createQuery(sb.toString()); query.setLockMode("Administrador", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:diagrama_bd.base_de_datos.CanalDAO.java
public static java.util.Iterator iterateCanalByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From diagrama_bd.base_de_datos.Canal as Canal"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/*from ww w . j a v a 2s .c o m*/ Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }