List of usage examples for org.hibernate Query iterate
Iterator<R> iterate();
From source file:controller.UrunIslemleri.java
public String[] urunAdiGetir() { String QUERY = "from urun"; int ekle = 0; org.hibernate.Query sorgu = session.createQuery(QUERY); Iterator it = sorgu.iterate(); ArrayList<String> liste = new ArrayList(); while (it.hasNext()) { urun urn = (urun) it.next();/* w w w . ja v a2s .c o m*/ liste.add(urn.getU_adi()); } String str[] = new String[liste.size()]; for (int i = 0; i < liste.size(); i++) { str[i] = liste.get(i); } return str; }
From source file:controller.UrunIslemleri.java
public DefaultTableModel urunGetir(String u_adi, DefaultTableModel tm) { String QUERY = "from urun where u_adi =:u_adi"; org.hibernate.Query sorgu = session.createQuery(QUERY); sorgu.setParameter("u_adi", u_adi); Iterator it = sorgu.iterate(); ArrayList<urun> liste = new ArrayList(); while (it.hasNext()) { urun urn = (urun) it.next();/*w w w . java 2s .c om*/ liste.add(urn); } for (int i = 0; i < liste.size(); i++) { tm.addRow(new Object[] { liste.get(i).getU_barkod(), liste.get(i).getU_adi(), liste.get(i).getU_marka(), liste.get(i).getU_kategori(), liste.get(i).getU_birim(), liste.get(i).getU_gelis(), liste.get(i).getU_satis(), liste.get(i).getU_raf(), liste.get(i).getU_kdv() }); } return tm; }
From source file:controller.UrunIslemleri.java
public DefaultTableModel urunGetir() { String QUERY = "from urun"; org.hibernate.Query sorgu = session.createQuery(QUERY); Iterator it = sorgu.iterate(); ArrayList<urun> liste = new ArrayList(); DefaultTableModel tm = new DefaultTableModel(); while (it.hasNext()) { urun urn = (urun) it.next();/*w w w.j a v a 2 s. c o m*/ liste.add(urn); } tm.addColumn("Barkod No"); tm.addColumn("rn Ad"); tm.addColumn("Marka"); tm.addColumn("Kategori"); tm.addColumn("Birim"); tm.addColumn("Geli Fiyat"); tm.addColumn("Sat Fiyat"); tm.addColumn("Raf"); tm.addColumn("KDV"); for (int i = 0; i < liste.size(); i++) { tm.addRow(new Object[] { liste.get(i).getU_barkod(), liste.get(i).getU_adi(), liste.get(i).getU_marka(), liste.get(i).getU_kategori(), liste.get(i).getU_birim(), liste.get(i).getU_gelis(), liste.get(i).getU_satis(), liste.get(i).getU_raf(), liste.get(i).getU_kdv() }); } return tm; }
From source file:corner.orm.hibernate.impl.PaginatedEntityService.java
License:Apache License
/** * /*from w ww . j ava2 s .c o m*/ * magic paginate method. * eg: * <code> * options.setPage(2); * * * paginate(Member.class,new Object[]{"email=?","asdf@asdf.net"},"userName desc",options) * paginate(Member.class,"email='asdf@asdf.net'","userName desc",options) * * List conditions = new ArrayList(); * conditions.add("userName=? and password=?"); * conditions.add(userName); * conditions.add(password); * paginate(Member.class,conditions,"userName desc",options) * * </code> * Magic conditions query criteria * @param persistClass persistence class * @param conditions query criteria * @param order order by sql * @param options pagination options. * @return include result and totalRecord. */ public PaginationList paginate(final Class<?> persistClass, final Object conditions, final String order, final PaginationOptions options) { final Iterable con = typeCoercer.coerce(conditions, Iterable.class); return (PaginationList) this.template.execute(new HibernateCallback() { /** * @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session) */ @Override public Object doInHibernate(Session session) throws HibernateException, SQLException { final Iterator it = con == null ? null : con.iterator(); String conditionHQL = buildConditionHQL(persistClass, it).toString(); //query list final StringBuffer queryHQL = new StringBuffer(conditionHQL); appendOrder(queryHQL, order); queryHQL.insert(0, SELECT_ID_CLAUSE); Query query = session.createQuery(queryHQL.toString()); //count query final StringBuffer countHQL = new StringBuffer(conditionHQL); countHQL.insert(0, "select count(*) "); Query countQuery = session.createQuery(countHQL.toString()); if (it != null) { int i = 0; while (it.hasNext()) { Object obj = it.next(); query.setParameter(i, obj); countQuery.setParameter(i, obj); i++; } } //get perpage int perPage = options.getPerPage(); int page = options.getPage(); if (page < 1) { page = 1; } query.setFirstResult((page - 1) * perPage); query.setMaxResults(perPage); //query total record number options.setTotalRecord((Long) countQuery.iterate().next()); ResultTransformer transformer = new LazyLoadEntityTransformer(session, persistClass); query.setResultTransformer(transformer); PaginationList list = new PaginationList(query.list().iterator(), options); return list; } }); }
From source file:corner.orm.hibernate.impl.PaginatedEntityService.java
License:Apache License
public long count(final Class<?> persistClass, final Object conditions) { return (Long) this.template.execute(new HibernateCallback() { /**// w ww . j a v a 2 s . c o m * @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session) */ @Override public Object doInHibernate(Session session) throws HibernateException, SQLException { Iterable con = typeCoercer.coerce(conditions, Iterable.class); final Iterator it = con == null ? null : con.iterator(); final StringBuffer sb = buildConditionHQL(persistClass, it); sb.insert(0, "select count(*) "); Query query = session.createQuery(sb.toString()); if (it != null) { int i = 0; while (it.hasNext()) { query.setParameter(i++, it.next()); } } return query.iterate().next(); } }); }
From source file:corner.orm.tapestry.table.RelativePersistentBasicTableModel.java
License:Apache License
/** * /*from w w w. jav a 2s. c om*/ * @see org.apache.tapestry.contrib.table.model.IBasicTableModel#getRowCount() */ public int getRowCount() { if (isRewinding) { return rows; } if (rows == -1) { final Collection c = this.getRelativeCollection(); if (c == null) { return 0; } //TODO ? Integer? Long rows = ((Long) this.entityService.execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = createQuery(session, c, "select count(*)", null); return query.iterate().next(); } })).intValue(); } return rows; }
From source file:corner.service.EntityService.java
License:Apache License
/** * ?/*from ww w. j av a 2s . co m*/ * * @param c ? * @return boolean * true: false:? */ public boolean isEmptyLazyCollection(final Collection c) { if (c == null) { return true; } int rows = ((Long) execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createFilter(c, SELECT_COUNT_HQL_STR); return query.iterate().next(); } })).intValue(); return rows == 0; }
From source file:corner.services.impl.EntityServiceImpl.java
License:Apache License
/** * @param queryString/*from w w w .ja va 2 s . com*/ * @param values * @return * @throws DataAccessException * @see org.springframework.orm.hibernate3.HibernateTemplate#find(java.lang.String, java.lang.Object[]) */ public Iterator<?> find(final String queryString, final Object[] values) throws DataAccessException { return (Iterator<?>) template.executeWithNativeSession(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query queryObject = session.createQuery(queryString); if (values != null) { for (int i = 0; i < values.length; i++) { queryObject.setParameter(i, values[i]); } } return queryObject.iterate(); } }); }
From source file:corner.services.impl.EntityServiceImpl.java
License:Apache License
/** * @param queryName/*from ww w .j a va2 s .com*/ * @param values * @return * @throws DataAccessException * @see org.springframework.orm.hibernate3.HibernateTemplate#findByNamedQuery(java.lang.String, java.lang.Object[]) */ public Iterator<?> findByNamedQuery(final String queryName, final Object[] values) throws DataAccessException { return (Iterator<?>) template.executeWithNativeSession(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query queryObject = session.getNamedQuery(queryName); if (values != null) { for (int i = 0; i < values.length; i++) { queryObject.setParameter(i, values[i]); } } return queryObject.iterate(); } }); }
From source file:corner.services.impl.EntityServiceImpl.java
License:Apache License
/** * @param queryName//from w w w.ja v a2 s . com * @param paramNames * @param values * @return * @throws DataAccessException * @see org.springframework.orm.hibernate3.HibernateTemplate#findByNamedQueryAndNamedParam(java.lang.String, java.lang.String[], java.lang.Object[]) */ public Iterator<?> findByNamedQueryAndNamedParam(final String queryName, final String[] paramNames, final Object[] values) throws DataAccessException { if (paramNames != null && values != null && paramNames.length != values.length) { throw new IllegalArgumentException("Length of paramNames array must match length of values array"); } return (Iterator<?>) template.executeWithNativeSession(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query queryObject = session.getNamedQuery(queryName); if (values != null) { for (int i = 0; i < values.length; i++) { applyNamedParameterToQuery(queryObject, paramNames[i], values[i]); } } return queryObject.iterate(); } }); }