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:accesobd.AccesoRolesVistas.java

License:BSD License

/**
 * Basado en este hql: from phone p where p.id not in (select ph.id from User u join u.phoneList ph)
 * Para ms info, ver http://stackoverflow.com/questions/9839114/hibernate-not-in-subquery-on-junction-table
 * //from   w  w  w. j av  a 2 s . co  m
 * Como una vista pertenece a un sistema, solo se deben buscar los roles de ese sistema.
 * 
 * @param vista
 * @return 
 */
public List<AdmRol> obtenerRolesQueNoEstanEnVista(AdmVista vista) {
    List<AdmRol> listaRoles = null;

    Session sesion;
    sesion = HibernateUtil.getSessionFactory().openSession();

    try {

        Query q = sesion.createQuery("from AdmRol where id not in (select  admRol.id" + " from AdmRolVista"
                + " where admVista.id = :vistaID)" + " and admSistema.id = :sistemaID ");
        q.setParameter("vistaID", vista.getId());
        q.setParameter("sistemaID", vista.getAdmSistema().getId());

        listaRoles = (List<AdmRol>) q.list();

    } catch (Exception e) {
        System.out.println(e.toString());
        LogUtil.log(Level.SEVERE,
                "Error al obtener la lista de roles que no estn en la vista " + e.toString());
    }

    sesion.close();

    return listaRoles;
}

From source file:accesobd.AccesoVistas.java

License:BSD License

/**
 * Retorna la lista de vistas para un sistema particular.
 * @param idSistema El identificador del sistema.
 * @return //  w ww  .  ja  v  a2s .c  om
 */
public List<AdmVista> obtenerVistasSistema(int idSistema) {
    List<AdmVista> listaVistas = null;

    Session sesion;
    sesion = HibernateUtil.getSessionFactory().openSession();

    try {

        Query q = sesion.createQuery("from AdmVista where admSistema.id = :idSistema");
        q.setParameter("idSistema", idSistema);

        listaVistas = (List<AdmVista>) q.list();

    } catch (Exception e) {
        System.out.println(e.toString());
    }

    sesion.close();

    return listaVistas;

}

From source file:accesobd.AccesoVistas.java

License:BSD License

/**
 * Obtiene una vista a partir de su identificador.
 * @param idVista/* w w  w . j a  v  a  2s .c o m*/
 * @return 
 */
public AdmVista obtenerVista(int idVista) {
    AdmVista vista;

    Session sesion;
    sesion = HibernateUtil.getSessionFactory().openSession();

    try {

        Query q = sesion.createQuery("from AdmVista where id = :id");
        q.setParameter("id", idVista);

        vista = (AdmVista) q.uniqueResult();

    } catch (Exception e) {
        vista = null;
        System.out.println(e.toString());
    } finally {
        sesion.close();
    }

    return vista;

}

From source file:acc_r3_javier_gonzalez.Consultas.java

/**
 * Metodo que devuelve una List con los resultados de la consulta con campo calculado.
 * Suma las cervezas de la misma marca que ha comprado cada Cliente.
 * @return (list<Calculado>) - lista con los datos a mostrar.
 *//*from  ww  w . j ava2s  . c o m*/
public static List consultaCalculado() {

    Session s = Conexion.getSession();
    String hql = "select new acc_r3_javier_gonzalez.bbdd.Calculado("
            + "v.vcliente, sum(v.vcantidad), c.cnombre) " + "from R3Ventas as v, R3Cerveza as c "
            + "where v.r3Cerveza.cid = c.cid " + "group by v.vcliente, c.cnombre order by v.vcliente";

    Query q = s.createQuery(hql);
    List<Calculado> l = q.list();
    Conexion.desconecta();
    return l;
}

From source file:acc_r3_javier_gonzalez.Consultas.java

/**
 * Metodo que devuelve una List con los resultados de la consulta con join.
 * Muestra datos de las tres tablas.// w ww . j a v  a  2  s  .  c  o  m
 * @return (List<Join>) - lista con los datos a mostrar.
 */
public static List consultaJoin() {
    Session s = Conexion.getSession();
    String hql = "select new acc_r3_javier_gonzalez.bbdd.Join("
            + "v.vcliente, t.tnombre, c.cnombre, v.vcantidad) "
            + "from R3Ventas as v, R3Cerveza as c, R3Tiendas as t "
            + "where v.r3Cerveza.cid = c.cid and v.r3Tiendas.tid = t.tid " + "order by v.vcliente";

    Query q = s.createQuery(hql);
    List<Calculado> l = q.list();
    Conexion.desconecta();
    return l;
}

From source file:acc_r3_javier_gonzalez.Consultas.java

/**
 * Metodo que devuelve toda la tabla R3Cerveza.
 * @return (List<R3Cerveza>) - lista con los resultados a mostrar.
 */// www.j  a  v a 2 s.  c  om
public static List consultaCerves() {

    Session s = Conexion.getSession();
    String hql = "from R3Cerveza";
    Query q = s.createQuery(hql);
    List<R3Cerveza> l = q.list();
    Conexion.desconecta();
    return l;
}

From source file:acc_r3_javier_gonzalez.Consultas.java

/**
 * Metodo que devuelve una cerveza concreta buscada por ID.
 * @param id (int) - id de la cerveza que se quiere recuperar.
 * @return (R3Cerveza) - cerveza que se devuelve, null si no est.
 *///from   w w  w  . j  av  a 2s. co  m
public static R3Cerveza searchById(int id) {
    Session s = Conexion.getSession();
    String hql = "from R3Cerveza where cid = :id";
    Query q = s.createQuery(hql);
    q.setInteger("id", id);
    R3Cerveza cerve = (R3Cerveza) q.uniqueResult();
    Conexion.desconecta();
    return cerve;
}

From source file:Action.OrderManagement.java

public String fillCompanyNames() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Company_Details company_Details;/*from   w w w . j  a v a 2  s  .  c  o  m*/
    Query q = s.createQuery(" from Company_Details");
    List<Company_Details> data = q.list();
    if (data.isEmpty()) {
    } else {
        for (Company_Details cid : data) {

            getCompanyNamesList().add(cid.getCompanyName());

        }
    }

    t.commit();
    return "success";
}

From source file:Action.OrderManagement.java

public String fillCompanyDetails() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Company_Details company_Details;/*from w  w  w  .j  a v  a2  s  .c om*/
    Query q = s.createQuery(" from Company_Details where companyName='" + getCompanyName() + "'");
    List<Company_Details> data = q.list();
    for (Company_Details sid : data) {
        setCity(sid.getCity());
        setProvince(sid.getProvince());
        setStreet1(sid.getStreet1());
        setStreet2(sid.getStreet2());
        setPincode(sid.getPincode());
        setEmailId(sid.getEmailId());
        setContactNo1(sid.getContactNo1());
        setContactNo2(sid.getContactNo2());
        setCompanyHead(sid.getCompanyHead());
    }
    t.commit();

    return "success";
}

From source file:Action.OrderManagement.java

public String addOrder() throws NullPointerException {
    Session s = HibernateUtil.getSession();
    Transaction t = s.beginTransaction();

    Company_Details company_Details;//from  w w w  .  j a  v a  2 s . co  m
    Query q1 = s.createQuery(" from Company_Details where companyName='" + getCompanyName() + "'");
    List<Company_Details> data1 = q1.list();
    company_Details = new Company_Details(0, getCompanyName(), getStreet1(), getStreet2(), getCity(),
            getProvince(), getPincode(), getEmailId(), getCompanyHead(), getContactNo1(), getContactNo2());

    if (data1.isEmpty()) {
        s.save(company_Details);
        System.out.println("sssss");
    }

    setNewMaterialRequired("  Pieces ." + "Material Required for Order  - 1. " + getName() + "  "
            + getQuantity() + "  Pieces   2. " + getName2() + "  " + getQuantity2());
    Order_Details order_Details;
    order_Details = new Order_Details(0, getOrderDescription(), getContactPerson(), "Pending", 0, 0,
            getNewMaterialRequired(), company_Details);
    s.save(order_Details);

    if (getName2().isEmpty()) {
    } else {
        Product_Details product_Details;
        product_Details = new Product_Details(0, getName(), getQuantity(), getRateFixed(), getDeliveryDate(),
                order_Details);
        s.save(product_Details);

        Product_Processing product_processing11;
        product_processing11 = new Product_Processing(0, 0, "Process 1", product_Details);
        s.save(product_processing11);
        Product_Processing product_processing12;
        product_processing12 = new Product_Processing(0, 0, "Process 2", product_Details);
        s.save(product_processing12);
        Product_Processing product_processing13;
        product_processing13 = new Product_Processing(0, 0, "Process 3", product_Details);
        s.save(product_processing13);
        Product_Processing product_processing14;
        product_processing14 = new Product_Processing(0, 0, "Process 4", product_Details);
        s.save(product_processing14);
        Product_Processing product_processing15;
        product_processing15 = new Product_Processing(0, 0, "Process 5", product_Details);
        s.save(product_processing15);
    }

    if (getName2().isEmpty()) {
    } else {
        Product_Details product_Details2;
        product_Details2 = new Product_Details(0, getName2(), getQuantity2(), getRateFixed2(),
                getDeliveryDate2(), order_Details);
        s.save(product_Details2);

        Product_Processing product_processing21;
        product_processing21 = new Product_Processing(0, 0, "Process 1", product_Details2);
        s.save(product_processing21);
        Product_Processing product_processing22;
        product_processing22 = new Product_Processing(0, 0, "Process 2", product_Details2);
        s.save(product_processing22);
        Product_Processing product_processing23;
        product_processing23 = new Product_Processing(0, 0, "Process 3", product_Details2);
        s.save(product_processing23);
        Product_Processing product_processing24;
        product_processing24 = new Product_Processing(0, 0, "Process 4", product_Details2);
        s.save(product_processing24);
        Product_Processing product_processing25;
        product_processing25 = new Product_Processing(0, 0, "Process 5", product_Details2);
        s.save(product_processing25);
    }
    /*  if(Name3.isEmpty()){        // To be corrected
    } else {
    Product_Details product_Details3;
    product_Details3 = new Product_Details( 0, Name3, Quantity3,rateFixed3,deliveryDate3,order_Details);
    s.save(product_Details3);
    Product_Details product_Details4;
    product_Details4 = new Product_Details( 0, Name4, Quantity4,rateFixed4,deliveryDate4,order_Details);
    s.save(product_Details4);
    Product_Details product_Details5;
    product_Details5 = new Product_Details( 0, Name5, Quantity5,rateFixed5,deliveryDate5,order_Details);
    s.save(product_Details5);
      }*/

    t.commit();

    return "success";
}