Example usage for org.hibernate Session createQuery

List of usage examples for org.hibernate Session createQuery

Introduction

In this page you can find the example usage for org.hibernate Session createQuery.

Prototype

@Override
    org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);

Source Link

Usage

From source file:at.thinkingco2.databasemanager.JourneyAccess.java

@SuppressWarnings("unchecked")
public List<JourneyBean> getJourneysWithoutDriver(Set<GroupBean> groups) {
    Session session = getSession();

    Set<GroupBean> groupSet = null;
    Iterator<GroupBean> it = null;
    ArrayList<JourneyBean> journeyList = new ArrayList<JourneyBean>();

    List<JourneyBean> temp = session.createQuery("FROM JourneyBean WHERE licenseNumber IS NULL").list();

    for (JourneyBean journey : temp) {
        groupSet = journey.getGroups();/*from w  w w  .  j  a  va2s  .  c  om*/
        it = groups.iterator();
        while (it.hasNext()) {
            if (groupSet.contains(it.next())) {
                journeyList.add(journey);
            }
        }
    }

    session.close();

    return journeyList;
}

From source file:at.thinkingco2.databasemanager.JourneyAccess.java

@SuppressWarnings("unchecked")
public List<JourneyBean> getJourneysByRouteID(Integer routeId) {
    Session session = getSession();
    List<JourneyBean> list = null;

    Query q = session.createQuery("FROM JourneyBean WHERE routeId = :routeId");
    q.setParameter("routeId", routeId);

    list = q.list();/*w w w  . ja  v a2 s .c o  m*/
    session.close();

    return list;

}

From source file:at.thinkingco2.databasemanager.JourneyAccess.java

public JourneyBean getJourney(int id) {
    Session session = getSession();

    Query q = session.createQuery("FROM JourneyBean WHERE journeyId = :id");
    q.setParameter("id", id);

    JourneyBean res = (JourneyBean) q.uniqueResult();
    session.close();// w  w w .  j a va 2 s.co  m

    return res;
}

From source file:at.thinkingco2.databasemanager.JourneyAccess.java

public JourneyBean getJourney(JourneyBean journeyBean) {
    Session session = getSession();

    Query q = session
            .createQuery("FROM JourneyBean WHERE description = :description AND arrivleTime = :arrivleTime");
    q.setParameter("description", journeyBean.getDescription());
    q.setParameter("arrivleTime", journeyBean.getArrivleTime());

    JourneyBean res = (JourneyBean) q.uniqueResult();
    session.close();/* w ww . j  a  v  a2s .  com*/

    return res;
}

From source file:attendance.ui.AttendanceSystem.java

private void executeHQLQuery(String hql) {
    try {/* w  ww  .j a va 2s  . co  m*/
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Query q = session.createQuery(hql);
        List resultList = q.list();
        displayResult(resultList);
        session.getTransaction().commit();
    } catch (HibernateException he) {
        he.printStackTrace();
    }
}

From source file:attendance.ui.TakeAttendence.java

private void updateAttendance() {
    try {/* w  w w  .  j  av a  2s.  c o  m*/
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        for (int i = 1; i < jTable1.getRowCount(); i++) {
            if (jTable1.getValueAt(i, 4).equals(false)) {
                continue;
            } else {
                String rollNo = (String) jTable1.getValueAt(i, 2);

                Query q = session.createQuery("from Attendance a where a.student=" + rollNo);
                Attendance a = (Attendance) q.uniqueResult();
                a.setIsPresent(true);
            }
        }
        session.getTransaction().commit();
        JOptionPane.showMessageDialog(this, "Attendance Updated Successfully");
    } catch (HibernateException he) {
        he.printStackTrace();
    }
}

From source file:au.com.nicta.ct.db.CtKeyValueProperties.java

License:Open Source License

public static Query queryLike(String key, Session s) {
    String hql = " FROM CtProperties p WHERE p.name LIKE ?";
    Query q = s.createQuery(hql);
    q.setString(0, key);/*from   ww  w  .ja v a  2  s.  co  m*/
    return q;
}

From source file:au.com.nicta.ct.db.CtKeyValueProperties.java

License:Open Source License

public static Query query(String key, Session s) {
    String hql = " FROM CtProperties p WHERE p.name = ?";
    Query q = s.createQuery(hql);
    q.setString(0, key);//from  w w  w .  j a v a 2 s  .c o  m
    return q;
}

From source file:au.com.nicta.ct.db.CtSession.java

License:Open Source License

public static List getObjects(Session s, String hql) {
    s.beginTransaction();//from w  ww  .  ja va2s.c  o  m
    Query q = s.createQuery(hql);
    List results = q.list();

    s.getTransaction().commit();

    return results;
}

From source file:au.com.nicta.ct.db.entities.CtEntityPropertiesTypesUtil.java

License:Open Source License

public static List<CtEntityPropertiesTypes> find(Session s, Class entityName, String propertyName) {

    String qs = " SELECT ctEPT" + " FROM CtEntityPropertiesTypes as ctEPT" + " WHERE";

    String prefix = "";
    if (entityName != null) {
        qs += prefix + " ctEPT.entityName = :entityName";
        prefix = " AND";
    }/*from w w  w . j  av a2 s.c  o  m*/
    if (propertyName != null) {
        qs += prefix + " ctEPT.name = :name";
        prefix = " AND";
    }

    Query q = s.createQuery(qs);

    if (entityName != null) {
        q.setString("entityName", CtEntityPropertiesUtil.getClassName(entityName));
    }
    if (propertyName != null) {
        q.setString("name", propertyName);
    }

    List<CtEntityPropertiesTypes> l = (List<CtEntityPropertiesTypes>) q.list();

    return l;
}