struts.dao.ViewBurgerDao.java Source code

Java tutorial

Introduction

Here is the source code for struts.dao.ViewBurgerDao.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package struts.dao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import struts.dto.OrderTable;
import struts.dto.BurgerTable;

/**
 *
 * @author Subhadra
 */
public class ViewBurgerDao {
    public ArrayList execute1(OrderTable ot) {

        SessionFactory sf = new Configuration().configure().buildSessionFactory();
        Session s = sf.openSession();
        //Session s1=sf.openSession();
        Transaction tx = s.beginTransaction();
        //Transaction tx1= s1.beginTransaction();
        Criteria q = s.createCriteria(OrderTable.class);
        q.add(Restrictions.gt("burger", 0));
        ArrayList<BurgerTable> list = new ArrayList();
        List<OrderTable> list1 = q.list();
        if (!list1.isEmpty()) {
            for (OrderTable st : list1) {
                BurgerTable sa1 = new BurgerTable();
                sa1.setOrderId(st.getOrderId());
                sa1.setQuantity(st.getSandwich());
                list.add(sa1);
                //s1.save(sa);
                //s.save(sa);

            }
            //tx.commit();
            //s1.close();
        }
        return list;
    }

}