Example usage for org.hibernate SQLQuery setParameter

List of usage examples for org.hibernate SQLQuery setParameter

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setParameter.

Prototype

@Override
    NativeQuery<T> setParameter(int position, Object val);

Source Link

Usage

From source file:com.vertec.daoimpl.ProjectDetailsDAOImpl.java

public String updateProjectDetails(ProjectDetails pd) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {/*w  ww.  j  ava2 s  . com*/

            SQLQuery query = session.createSQLQuery(
                    "Update project_details set from_date=:fdate,to_date=:tdate,status_id=:staId,remark=:remk where project_proposal_id=:ppId");

            query.setParameter("fdate", pd.getFromDate());
            query.setParameter("tdate", pd.getToDate());
            query.setParameter("remk", pd.getRemark());
            query.setParameter("staId", pd.getStatusId().getId());
            query.setParameter("ppId", pd.getProjectProposalId().getId());
            //                query.setParameter("addBy", pd.getAddedBy());

            query.executeUpdate();

            transaction.commit();
            return VertecConstants.UPDATED;

        } catch (Exception e) {
            e.printStackTrace();
            return VertecConstants.ERROR;
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }

    }

    return null;
}

From source file:com.vertec.daoimpl.ProjectDetailsDAOImpl.java

public String DeleteEmployeeByDetailsId(int id) {
    int detailsId = viewPdIdByProposalId(id);
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    String result = "done";
    if (session != null) {
        try {/*from ww w.ja  v a2s. c  o  m*/
            SQLQuery query = session
                    .createSQLQuery("DELETE FROM project_has_employee WHERE project_details_id =:pId ");

            query.setParameter("pId", detailsId);

            query.executeUpdate();

            transaction.commit();
            return result;

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}

From source file:com.vertec.daoimpl.ProjectProcessDAOImpl.java

public String DeleteProcessById(int id) {

    Session session = NewHibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {//w w w  .j a va  2  s . c  o  m
            SQLQuery query = session.createSQLQuery("DELETE FROM project_process WHERE id =:pId ");

            query.setParameter("pId", id);

            query.executeUpdate();

            transaction.commit();
            return VertecConstants.UPDATED;

        } catch (Exception e) {
            e.printStackTrace();
            return VertecConstants.ERROR;
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}

From source file:com.vertec.daoimpl.ReportDAOImpl.java

public List<Object[]> invoiceItemToReport(int invoiceId) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    org.hibernate.Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {//  w ww . j a v  a 2  s.c  om

            SQLQuery query = session.createSQLQuery(
                    "SELECT p.product_name,ii.unit_price,ii.quantity,ii.tot_amount,ii.discount,ii.tot_after_dis FROM invoice_item ii inner join product_master pm on ii.product_master_id=pm.product_master_id\n"
                            + "inner join product p on pm.product_id=p.product_id\n"
                            + "where ii.invoice_id=:invoiceId");
            query.setParameter("invoiceId", invoiceId);

            List<Object[]> inList = query.list();
            return inList;

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}

From source file:com.vertec.daoimpl.ReportDAOImpl.java

public Object[] invoiceHeaderToReport(int invoiceId) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    org.hibernate.Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {/*  w  ww . j  a  v a2s.  c  o m*/

            SQLQuery query = session.createSQLQuery(
                    "SELECT i.invoice_id,i.invoiced_date,i.invoice_total,i.discount,i.tot_after_discount,c.customer_name,c.address as cadd,b.address as badd,b.contact_no,sum(i.tot_after_discount-(i.invoice_total-i.discount)) as tax\n"
                            + "FROM invoice i inner join customer c on i.customer_id=c.customer_id inner join branch b on i.branch_id=b.branch_id\n"
                            + "where i.invoice_id=:invoiceId");
            query.setParameter("invoiceId", invoiceId);
            Object[] invoice = (Object[]) query.uniqueResult();
            return invoice;

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}

From source file:com.vertec.daoimpl.ReportDAOImpl.java

public List<Object[]> dailyInvoiceReport(String selectDate) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    org.hibernate.Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {/*from  www. j  a va 2 s .c o  m*/

            SQLQuery query = session.createSQLQuery(
                    "SELECT i.invoice_id,c.customer_name,b.branch_name,i.invoice_total,i.discount,i.tot_after_discount,i.invoiced_date\n"
                            + "FROM invoice i inner join customer c on i.customer_id=c.customer_id inner join branch b on i.branch_id=b.branch_id\n"
                            + "where i.invoiced_date=:selectDate");
            query.setParameter("selectDate", selectDate);

            List<Object[]> inList = query.list();
            return inList;

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}

From source file:com.vertec.daoimpl.ReportDAOImpl.java

public List<Object[]> periodicallyInvoiceReport(String[] daeArr) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    org.hibernate.Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {/* ww w . j av a2 s  . c  o m*/

            SQLQuery query = session.createSQLQuery(
                    "SELECT i.invoice_id,c.customer_name,b.branch_name,i.invoice_total,i.discount,i.tot_after_discount,i.invoiced_date\n"
                            + "FROM invoice i inner join customer c on i.customer_id=c.customer_id inner join branch b on i.branch_id=b.branch_id\n"
                            + "where i.invoiced_date between :fromDate and :toDate");
            query.setParameter("fromDate", daeArr[0]);
            query.setParameter("toDate", daeArr[1]);

            List<Object[]> inList = query.list();
            return inList;

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}

From source file:com.vertec.daoimpl.ReportDAOImpl.java

public List<Object[]> branchWiseProduct(int branchId) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    org.hibernate.Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {//from w ww  .  j  a va 2s  . c o  m

            SQLQuery query = session.createSQLQuery(
                    "SELECT p.product_name,p.product_code,pm.selling_price,bp.quantity FROM branch_productmaster bp inner join product_master pm on bp.product_master_id=pm.product_master_id\n"
                            + "inner join branch b on bp.branch_id=b.branch_id\n"
                            + "inner join product p on pm.product_id=p.product_id\n"
                            + "where b.branch_id=:branchId");
            query.setParameter("branchId", branchId);
            List<Object[]> inList = query.list();
            return inList;

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}

From source file:com.vertec.daoimpl.ReportDAOImpl.java

public List<Object[]> branchWiseProductMaster(int branchId) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    org.hibernate.Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {//from w  w  w.j a  v  a 2s.c om

            SQLQuery query = session.createSQLQuery("SELECT p.product_name,p.product_code,bs.quantity\n"
                    + "FROM branch_stock bs inner join branch b on bs.branch_id=b.branch_id\n"
                    + "inner join product p on bs.product_id=p.product_id\n" + "where b.branch_id=:branchId");
            query.setParameter("branchId", branchId);
            List<Object[]> inList = query.list();
            return inList;

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}

From source file:com.vertec.daoimpl.ReportDAOImpl.java

public List<Object[]> releaseProductBranchWise(String[] date, int branchId) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    org.hibernate.Transaction transaction = session.beginTransaction();

    if (session != null) {
        try {//from  w  w w .j  a  v a 2  s.c om

            SQLQuery query = session.createSQLQuery(
                    "SELECT p.product_name,p.product_code,pm.selling_price,sum(ii.quantity) as pQuan\n"
                            + "FROM invoice_item ii inner join invoice i on ii.invoice_id=i.invoice_id\n"
                            + "inner join product_master pm on ii.product_master_id=pm.product_master_id\n"
                            + "inner join product p on pm.product_id=p.product_id\n"
                            + "inner join branch b on i.branch_id=b.branch_id\n"
                            + "where b.branch_id=:branchId and i.invoiced_date between :fromDate and :toDate group by pm.product_master_id");
            query.setParameter("branchId", branchId);
            query.setParameter("fromDate", date[0]);
            query.setParameter("toDate", date[1]);
            List<Object[]> inList = query.list();
            return inList;

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}