Example usage for org.hibernate Query setParameter

List of usage examples for org.hibernate Query setParameter

Introduction

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

Prototype

@SuppressWarnings("unchecked")
Query<R> setParameter(int position, Object val);

Source Link

Document

Bind a positional query parameter using its inferred Type.

Usage

From source file:automatedbillingsoftware_DA.Categories_DA.java

public Categories fetchCategoryById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Categories c where c.catid =:catid AND c.status=:status");
    query.setParameter("catid", id);
    query.setParameter("status", 1);
    List<Categories> catList = (List<Categories>) query.list();
    Categories cat = new Categories();
    if (catList.size() > 0) {
        cat = catList.get(0);/*from  w  w  w .ja  va  2  s  .c o m*/
    }
    beginTransaction.commit();
    return cat;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public ChallanGenerated fetchChallanGenById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from ChallanGenerated where status=:status and id=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<ChallanGenerated> challanList = (List<ChallanGenerated>) query.list();
    beginTransaction.commit();//from w  w  w .  j  a v  a  2  s  .c  om

    return (challanList == null || challanList.size() == 0) ? null : challanList.get(0);
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public Challan fetchChallanByDocNo(String docNo) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Challan where docNo =:docNo");
    query.setParameter("docNo", docNo);
    Challan challan = (Challan) query.list().get(0);
    beginTransaction.commit();/*  w  w  w  .  ja v a 2  s.  c o m*/
    return challan;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public List<ChallanGenerated> fetchChallanOrders() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from ChallanGenerated where status=:status");
    query.setParameter("status", 1);
    List<ChallanGenerated> challanList = (List<ChallanGenerated>) query.list();
    beginTransaction.commit();//ww  w .  ja va2s  .c o m

    return challanList;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public Challan fetchChallanById(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Challan where status=:status AND id=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<Challan> challanList = (List<Challan>) query.list();
    beginTransaction.commit();//from  w w  w.j  a va 2 s. c om

    return challanList == null || challanList.size() <= 0 ? null : challanList.get(0);
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public Challan fetchChallansByDocNameAndDocNo(String docName) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Challan where status=:status AND documentName LIKE :docName");
    query.setParameter("status", 1);
    query.setParameter("docName", docName);

    List<Challan> challanList = (List<Challan>) query.list();
    beginTransaction.commit();//  w w  w.j av a  2s  . c o  m

    return challanList == null ? null : challanList.get(0);
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public List<Challan> fetchAllChallanList() {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Challan where status=:status");
    query.setParameter("status", 1);
    List<Challan> challanList = (List<Challan>) query.list();
    beginTransaction.commit();//from www  .  ja  va 2  s. c om

    return challanList;
}

From source file:automatedbillingsoftware_DA.ChallanDA.java

public void deleteChallan(int id) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    Query query = session.createQuery("from Challan where status=:status AND id=:id");
    query.setParameter("status", 1);
    query.setParameter("id", id);
    List<Challan> challanList = (List<Challan>) query.list();
    Challan challan = challanList.get(0);
    challan.setStatus(0);/*from   www .ja  v  a  2  s  .c  o m*/
    session.update(challan);
    beginTransaction.commit();
}

From source file:automatedbillingsoftware_DA.CompanyDetailsDA.java

public Company fetchCompanyDetailsByUserIdandPass(String user, String pass) {
    Company comp = null;/*from  w  w w.  j  a  v a  2 s.  c om*/
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    Query query = session.createQuery("from Company comp where comp.password=:pass and comp.name=:name");
    query.setParameter("name", user);
    query.setParameter("pass", pass);
    List list = query.list();
    if (list != null && list.size() > 0) {
        comp = (Company) list.get(0);
    }
    session.getTransaction().commit();
    return comp;
}

From source file:automatedbillingsoftware_DA.CompanyDetailsDA.java

public void updateCurrentCompany(Company comp) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();// ww w . ja v  a  2 s . c o  m
    Query query = session.createQuery("from Company c where c.companyId=:id");
    query.setParameter("id", UserSession.getCompany().getCompanyId());
    Company com = (Company) query.list().get(0);
    com.setAddress(comp.getAddress());
    com.setCompanyName(comp.getCompanyName());
    com.setCountry(comp.getCountry());
    com.setDateOfInsertion(comp.getDateOfInsertion());
    com.setEmail(comp.getEmail());
    com.setLogo(comp.getLogo());
    com.setName(comp.getName());
    com.setPanNo(comp.getPanNo());
    com.setPassword(comp.getPassword());
    com.setPhone(comp.getPhone());
    com.setStatus(1);
    com.setTax(comp.getTax());
    com.setVatNo(comp.getVatNo());
    com.setWebsite(comp.getWebsite());

    session.update(com);
    UserSession.setCompany(com);
    session.getTransaction().commit();

}