Example usage for org.hibernate Query iterate

List of usage examples for org.hibernate Query iterate

Introduction

In this page you can find the example usage for org.hibernate Query iterate.

Prototype

Iterator<R> iterate();

Source Link

Document

Return the query results as an Iterator.

Usage

From source file:com.sapienter.jbilling.server.process.db.BillingProcessDAS.java

License:Open Source License

public Iterator getCountAndSum(Integer processId) {
    final String hql = "select count(id), sum(total), currency.id " + "  from InvoiceDTO "
            + " where billingProcess.id = :processId " + " group by currency.id";

    Query query = getSession().createQuery(hql);
    query.setParameter("processId", processId);
    return query.iterate();
}

From source file:com.sapienter.jbilling.server.process.db.BillingProcessDAS.java

License:Open Source License

/**
 * Search succesfull payments in Payment_Invoice map (with quantity > 0)
 * and returns result, groupped by currency
 *
 * @param processId//  www  . j  av a 2 s. c  om
 * @return Iterator with currency, method and sum of amount fields of query
 */
public Iterator getSuccessfulProcessCurrencyMethodAndSum(Integer processId) {
    final String hql = "select invoice.currency.id, method.id, sum(invoice.total) "
            + "  from InvoiceDTO invoice inner join invoice.paymentMap paymentMap "
            + " join paymentMap.payment payment join payment.paymentMethod method "
            + " where invoice.billingProcess.id = :processId and paymentMap.amount > 0"
            + " group by invoice.currency.id, method.id " + " having sum(invoice.total) > 0";

    Query query = getSession().createQuery(hql);
    query.setParameter("processId", processId);
    return query.iterate();
}

From source file:com.sapienter.jbilling.server.process.db.BillingProcessDAS.java

License:Open Source License

/**
 * Selection records from Invoice table without payment records or
 * with payments of 0 amount. Result groupped by currency
 * @param processId// w  w  w .  j  av a2  s.c  o m
 * @return Iterator with currency and amount value
 */
public Iterator getFailedProcessCurrencyAndSum(Integer processId) {
    final String hql = "select invoice.currency.id, sum(invoice.total) "
            + "  from InvoiceDTO invoice left join invoice.paymentMap paymentMap"
            + " where invoice.billingProcess.id = :processId and (paymentMap is NULL or paymentMap.amount = 0) "
            + " group by invoice.currency.id";

    Query query = getSession().createQuery(hql);
    query.setParameter("processId", processId);
    return query.iterate();
}

From source file:com.syncnapsis.tests.HibernateConfigurationTestCase.java

License:Open Source License

@SuppressWarnings("rawtypes")
public void testColumnMapping() throws Exception {
    logger.debug("testing column mapping...");

    Map metadata = HibernateUtil.currentSession().getSessionFactory().getAllClassMetadata();
    for (Object o : metadata.values()) {
        EntityPersister persister = (EntityPersister) o;
        String className = persister.getEntityName();
        logger.debug("Trying select * from: " + className);
        Query q = HibernateUtil.currentSession().createQuery("from " + className + " c");
        q.iterate();
        logger.debug("ok: " + className);
    }/*  ww w  . ja v  a 2  s .  com*/
}

From source file:com.trailmagic.user.UserLoginModule.java

License:Open Source License

private boolean validate(String username, char[] password) throws Exception {

    boolean valid = false;
    User user;/*from w  w w .  j  a  v a 2s. c o  m*/
    Session sess = null;

    try {
        sess = m_sessFactory.openSession();

        // validate with the User from hibernate
        Query query = sess.getNamedQuery(USER_BY_SN_QUERY);
        query.setString("screenName", username);

        //            user = (User)query.uniqueResult();
        Object obj = query.uniqueResult();
        //            System.err.println("uniqueResult returned a " + obj.getClass());
        user = (User) obj;
        if (user == null) {
            return false;
        }

        String storedPass = user.getPassword();

        if (storedPass != null && password != null && password.length > 0) {

            String digest = encodePassword(password);
            valid = storedPass.equals(digest);
            //                s_log.debug("digest = " + digest);
        }

        if (valid) {
            m_principals.add(new UserPrincipal(user.getScreenName()));
            query = sess.getNamedQuery(GROUPS_QUERY);
            query.setLong("userId", user.getId());
            Iterator iter = query.iterate();
            Collection<GroupPrincipal> groups = new ArrayList<GroupPrincipal>();
            while (iter.hasNext()) {
                groups.add(new GroupPrincipal(((Group) iter.next()).getName()));
            }
            m_principals.addAll(groups);
        }
    } catch (HibernateException e) {
        s_log.error("Hibernate error validating credentials", e);
    } finally {
        if (sess != null) {
            try {
                sess.close();
            } catch (HibernateException e) {
                s_log.error("Error closing session", e);
            }
        }
    }

    return valid;
}

From source file:controller.Giris.java

public int Giris(String username, String password) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();/* w  w w  . j  av a  2  s . c o  m*/
    String QUERY = "from kullanici";

    org.hibernate.Query sorgu = session.createQuery(QUERY);
    Iterator it = sorgu.iterate();
    ArrayList<kullanici> liste = new ArrayList();
    int giris = 0;
    while (it.hasNext()) {
        kullanici usr = (kullanici) it.next();
        liste.add(usr);
    }
    for (int i = 0; i < liste.size(); i++) {
        if (liste.get(i).getPassword().equals(password) && liste.get(i).getUsername().equals(username)) {
            if (liste.get(i).getK_yetki().equals("1"))
                giris = 1;
            else
                giris = 2;
        }

    }
    return giris;
}

From source file:controller.KategoriIslemleri.java

public void kategoriEkle(kategori ktgr) {
    String QUERY = "from  kategori";
    int ekle = 0;
    org.hibernate.Query sorgu = session.createQuery(QUERY);
    Iterator it = sorgu.iterate();
    ArrayList<kategori> liste = new ArrayList();
    while (it.hasNext()) {
        kategori ktgr2 = (kategori) it.next();
        liste.add(ktgr2);/*from ww  w  . ja  v a  2  s  . c  o  m*/
    }
    for (int i = 0; i < liste.size(); i++) {
        if (liste.get(i).getKategori_ad().equals(ktgr.getKategori_ad())) {
            JOptionPane.showMessageDialog(null, "Bu Kategori Zaten Mevcut");
            ekle = 1;
        }
    }
    if (ekle == 0) {
        session.saveOrUpdate(ktgr);
        ts.commit();
    }
}

From source file:controller.KategoriIslemleri.java

public String[] kategoriGetir() {
    String QUERY = "from  kategori";
    int ekle = 0;
    org.hibernate.Query sorgu = session.createQuery(QUERY);
    Iterator it = sorgu.iterate();
    ArrayList<kategori> liste = new ArrayList();
    while (it.hasNext()) {
        kategori ktgr2 = (kategori) it.next();
        liste.add(ktgr2);/* w w  w . j a v  a  2 s  . c om*/
    }
    String obj[] = new String[liste.size()];
    for (int i = 0; i < liste.size(); i++) {
        obj[i] = liste.get(i).getKategori_ad();

    }
    return obj;
}

From source file:controller.KullaniciIslemleri.java

public int KullaniciEkle(String username, String password) {

    String QUERY = "from kullanici";
    int ekle = 0;
    org.hibernate.Query sorgu = session.createQuery(QUERY);
    Iterator it = sorgu.iterate();
    ArrayList<kullanici> liste = new ArrayList();
    while (it.hasNext()) {
        kullanici usr = (kullanici) it.next();
        liste.add(usr);/*from w  w w .j a va  2 s. c  o m*/
    }
    if (username.trim().equals("") && password.trim().equals("")) {
        JOptionPane.showMessageDialog(null, "Kullanc ad veya ifre alan bo braklamaz");
        return 1;
    } else {
        for (int i = 0; i < liste.size(); i++) {
            if (liste.get(i).getUsername().equals(username)) {

                ekle = 1;
            }
        }
        if (ekle == 0) {
            model.kullanici usr = new kullanici();
            usr.setUsername(username);
            usr.setPassword(password);
            usr.setK_yetki("2");
            JOptionPane.showMessageDialog(null, "Baari ile Eklendi");
            session.saveOrUpdate(usr);
            ts.commit();
        } else
            JOptionPane.showMessageDialog(null, "Boyle bir kullanc zaten mevcut");
    }
    return ekle;
}

From source file:controller.KullaniciIslemleri.java

public DefaultTableModel KullaniciGetir() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();//from   w  w  w . j  a v  a2  s  .co m
    String QUERY = "from kullanici";

    org.hibernate.Query sorgu = session.createQuery(QUERY);
    Iterator it = sorgu.iterate();
    ArrayList<kullanici> liste = new ArrayList();
    DefaultTableModel tm = new DefaultTableModel();
    while (it.hasNext()) {
        kullanici usr = (kullanici) it.next();

        liste.add(usr);
    }
    tm.addColumn("Kullanc no");
    tm.addColumn("Kullanc Ad");
    tm.addColumn("Kullanc ifresi");
    tm.addColumn("Yetki");

    for (int j = 0; j < liste.size(); j++) {
        tm.addRow(new Object[] { liste.get(j).getK_id(), liste.get(j).getUsername(), liste.get(j).getPassword(),
                liste.get(j).getK_yetki() });
    }

    return tm;
}