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:backend.api.StorageManagement.java

public Category getAttributes(int idAttributes) //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {/*from  w ww .  j av a2 s.c  o  m*/

        Query query = s.createQuery("select a from Attributes a where a.idCategory='" + idAttributes + "'");

        List<Category> category = query.list();
        if (category.isEmpty() || category.size() == 0)
            return null;
        return (Category) category.get(0);

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public Category getAttributes(String name) //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//w ww  . j a va  2  s  . c  o  m

        Query query = s.createQuery("select a from Attributes a where a.name='" + name + "'");

        List<Category> category = query.list();
        if (category.isEmpty() || category.size() == 0)
            return null;
        return (Category) category.get(0);

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public List<FinanceRegister> getFinanceRegisterRecords() // ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//w  w  w. jav  a  2s.  c  om

        Query query = s.createQuery("select fr from FinanceRegister fr");

        List<FinanceRegister> fr = query.list();
        return fr;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}

From source file:backend.api.View.java

public boolean checkAuthorization(String name, String password) // ok
{
    Session s = sf.openSession();
    try {// w  w w .  j a v a2s.c o m

        Query q = s.createQuery(
                "select u from Users u where u.name='" + name + "' and u.password='" + password + "'");
        List<Users> result = q.list();
        if (result.isEmpty() || result.size() == 0)
            return false;
        return true;

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        s.close();
    }
}

From source file:backend.api.View.java

public List<Users> getAllUsers() // ok
{
    Session s = sf.openSession();
    try {/*  w w w.  j av  a2  s. com*/

        Query query = s.createQuery("select u from Users u");

        List<Users> users = query.list();
        return users;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}

From source file:backend.core.controller.UserController.java

public Users getUsersByGroupId(int id) {

    Users user;//  w  w w  .j a v  a  2 s.c om

    Session s = getInstance().openSession();
    try {
        //pracownik = (Pracownik) s.load(Pracownik.class, id);

        Query query = s.createQuery("select u from Users u where " + "idusers = " + id);

        user = (Users) query.list().get(0);

    } finally {
        s.close();
    }

    return user;
}

From source file:baking.dao.BaseDao.java

License:Open Source License

/**
 * HQL?//from   w  w  w .  j  a va 2 s .  c  o  m
 * @param hql 
 * @return list
 */
public List find(final String hql) {
    try {
        Session session = getSession();
        return session.createQuery(hql).list();
    } catch (RuntimeException re) {
        throw re;
    }
}

From source file:baking.dao.BaseDao.java

License:Open Source License

/**
 * HQL?//w ww  .j  a v a 2  s .  co m
 * @param hql 
 * @param value ?
 * @return list
 */
public List find(final String hql, final Object value) {
    try {
        Session session = getSession();
        return session.createQuery(hql).setParameter(0, value).list();
    } catch (RuntimeException re) {
        throw re;
    }
}

From source file:baking.dao.BaseDao.java

License:Open Source License

/**
 * HQL?.//from w ww.  ja  va 2 s  .c  om
 * 
 * @param hql 
 * @param values ?
 * @return list
 */
public List find(final String hql, final Object[] values) {
    try {
        Session session = getSession();
        Query query = session.createQuery(hql);
        for (int i = 0; i < values.length; i++) {
            query.setParameter(i, values[i]);
        }
        return query.list();
    } catch (RuntimeException re) {
        throw re;
    }
}

From source file:baking.dao.BaseDao.java

License:Open Source License

/**
 * HQL?/*from  ww w  .  j  av  a 2  s  .c  o  m*/
 * @param hql HQL?
 * @param offset ???
 * @param pageSize ??
 * @return ?list
 */
public List findList(final String hql, final int offset, final int pageSize) {
    try {
        Session session = getSession();
        return session.createQuery(hql).setFirstResult(offset).setMaxResults(pageSize).list();
    } catch (RuntimeException re) {
        throw re;
    }
}