Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

In this page you can find the example usage for org.hibernate Session load.

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

From source file:com.celements.payment.service.PayPalService.java

License:Open Source License

public PayPal loadPayPalObject(final String txnId) throws XWikiException {
    boolean bTransaction = true;

    PayPal payPalObj = new PayPal();
    payPalObj.setTxn_id(txnId);//from w  w  w. j a  v  a2 s  .c  om

    getStore().checkHibernate(getContext());

    SessionFactory sfactory = getStore().injectCustomMappingsInSessionFactory(getContext());
    bTransaction = bTransaction && getStore().beginTransaction(sfactory, false, getContext());
    Session session = getStore().getSession(getContext());
    session.setFlushMode(FlushMode.MANUAL);

    try {
        session.load(payPalObj, payPalObj.getTxn_id());
    } catch (ObjectNotFoundException exp) {
        LOGGER.debug("no paypal object for txn_id [" + payPalObj.getTxn_id() + "] in" + " database ["
                + getContext().getDatabase() + "] found.");
        // No paypall object in store
    }
    LOGGER.trace("successfully loaded paypal object for txn_id [" + payPalObj.getTxn_id() + "] in database ["
            + getContext().getDatabase() + "] :" + payPalObj.getOrigMessage());
    return payPalObj;
}

From source file:com.celements.payment.service.PostFinanceService.java

License:Open Source License

public PostFinance loadPostFinanceObject(final String txnId) throws XWikiException {
    boolean bTransaction = true;

    PostFinance postFinanceObj = new PostFinance();
    postFinanceObj.setTxn_id(txnId);/*from ww w.j a  v a  2  s.c  o m*/

    getStore().checkHibernate(getContext());

    SessionFactory sfactory = getStore().injectCustomMappingsInSessionFactory(getContext());
    bTransaction = bTransaction && getStore().beginTransaction(sfactory, false, getContext());
    Session session = getStore().getSession(getContext());
    session.setFlushMode(FlushMode.MANUAL);

    try {
        session.load(postFinanceObj, postFinanceObj.getTxn_id());
    } catch (ObjectNotFoundException exp) {
        LOGGER.debug("no PostFinance object for txn_id [" + postFinanceObj.getTxn_id() + "] in" + " database ["
                + getContext().getDatabase() + "] found.");
        // No PostFinancel object in store
    }
    LOGGER.trace("successfully loaded PostFinance object for txn_id [" + postFinanceObj.getTxn_id()
            + "] in database [" + getContext().getDatabase() + "] :" + postFinanceObj.getOrigMessage());
    return postFinanceObj;
}

From source file:com.certus.actions.AddCategoryAction.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    switch (request.getParameter("status")) {
    case "save":
        if (!request.getParameter("cat_name").equals("")) {
            Session session = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();//  w ww.j a  v  a  2 s . c  o  m
            Category category = new Category(request.getParameter("cat_name"),
                    Integer.parseInt(request.getParameter("aval")) != 0);
            session.save(category);
            session.getTransaction().commit();
            session.close();
        } else {
            response.getWriter().write("Category Name is missing !");
        }
        break;
    case "update":
        if (!request.getParameter("cat_name").equals("")) {
            Session session = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            Category category = (Category) session.load(Category.class,
                    Integer.parseInt(request.getParameter("cat_id")));
            category.setCatName(request.getParameter("cat_name").toLowerCase());
            category.setAvailability(Integer.parseInt(request.getParameter("aval")) != 0);
            session.update(category);
            session.getTransaction().commit();
            session.close();
        } else {
            response.getWriter().write("Category Name is missing !");
        }
        break;
    }
}

From source file:com.certus.actions.addNewProAction.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getParameter("proPrice") != null && request.getParameter("proName") != null) {
        Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
        Category c = (Category) s.load(Category.class,
                Integer.parseInt(request.getParameter("proCat").split(">")[0].trim()));
        SubCategory sub = (SubCategory) s.load(SubCategory.class,
                Integer.parseInt(request.getParameter("proCat").split(">")[1].trim()));
        Brand b = (Brand) s.load(Brand.class, Integer.parseInt(request.getParameter("selBrand").trim()));
        Size size = (Size) s.load(Size.class, Integer.parseInt(request.getParameter("proSize").trim()));
        String proName = request.getParameter("proName");
        double price = Double.parseDouble(request.getParameter("proPrice").trim());
        if (request.getParameter("esnHid").isEmpty()) {
            s.beginTransaction();/*from ww w. j  a  va  2  s  .  c  o  m*/
            Product pro = new Product();
            pro.setBrand(b);
            pro.setSpecs("<tbody></tbody>");
            pro.setSubCategory(sub);
            pro.getSubCategory().setCategory(c);
            pro.setName(proName);
            ProductHasSize phs = new ProductHasSize();
            phs.setProduct(pro);
            phs.setPrice(price);
            phs.setSize(size);
            s.save(phs);
            s.getTransaction().commit();
            s.close();
        } else {
            Product pro = (Product) s.createCriteria(Product.class, "pro")
                    .add(Restrictions.eq("pro.name", proName)).list().get(0);
            s.beginTransaction();
            ProductHasSize phs = new ProductHasSize();
            phs.setProduct(pro);
            phs.setPrice(price);
            phs.setSize(size);
            s.save(phs);
            s.getTransaction().commit();
            s.close();
        }
        response.sendRedirect("products.jsp");

    }

}

From source file:com.certus.actions.addNewPropertyAction.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getParameter("propName") != null && request.getParameter("descrip") != null
            && request.getParameter("pid") != null) {
        Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
        s.beginTransaction();//  www.  j av  a2s . c  o m
        Product p = (Product) s.load(Product.class, Integer.parseInt(request.getParameter("pid")));
        String html = "<table>" + p.getSpecs() + "</table>";
        Document doc = Jsoup.parse(html);
        Elements elements = doc.select("tbody");

        elements.last().append("<tr><td><strong>" + request.getParameter("propName") + "</strong></td><td>"
                + request.getParameter("descrip") + "</td></tr>");
        p.setSpecs(doc.body().select("table").html());
        s.update(p);
        s.getTransaction().commit();
        s.close();
        response.sendRedirect(
                "edit_product.jsp?pid=" + request.getParameter("pid") + "&sid=" + request.getParameter("sid"));

    }

}

From source file:com.certus.actions.addToWishListAction.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
    Product p = (Product) s.load(Product.class, Integer.parseInt(request.getParameter("pid")));
    User u = (User) request.getSession().getAttribute("user");
    if (p != null & u != null) {
        WishList list = new WishList();
        s.beginTransaction();/*from  w w w .  j  a v a 2s.c  o  m*/
        list.setDateAdded(new Date(new java.util.Date().getTime()));
        list.setProduct(p);
        list.setUser(u);
        s.save(list);
        s.getTransaction().commit();
        s.close();
        response.getWriter().write("Successfully added to the wish-list !");
    } else if (u == null) {
        response.getWriter().write("You have to login first.");
    }
}

From source file:com.certus.actions.adminEditProfileAction.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
    BasicPasswordEncryptor encriptor = new BasicPasswordEncryptor();
    String logName = request.getParameter("logName");
    String fName = request.getParameter("fName");
    String lname = request.getParameter("lName");
    String email = request.getParameter("email");
    String pass = request.getParameter("pass");
    String conpass = request.getParameter("conpass");
    Administor ad = (Administor) request.getSession(false).getAttribute("admin");
    if (logName != null && !logName.isEmpty() && fName != null && !fName.isEmpty() && lname != null
            && !lname.isEmpty() && email != null && !email.isEmpty()) {
        Administor admin = (Administor) s.load(Administor.class, ad.getId());
        s.beginTransaction();/* ww  w  . j  a  v a2  s. c o m*/
        admin.setEmail(email);
        admin.setFName(fName);
        admin.setLName(lname);
        admin.setUserName(logName);
        if (pass.equals(conpass) && !pass.isEmpty() && !conpass.isEmpty()) {
            admin.setPassword(encriptor.encryptPassword(pass));
        }
        s.update(admin);
        s.getTransaction().commit();
        s.close();
        response.getWriter().write("success");
    }
}

From source file:com.certus.actions.adminOrderEditAction.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
    int oid = Integer.parseInt(request.getParameter("oid"));
    Order order = (Order) s.load(Order.class, oid);

}

From source file:com.certus.actions.chooseFeaturedProAction.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // System.out.println(request.getParameter("pid") + " - " + request.getParameter("fpid"));
    int pid = Integer.parseInt(request.getParameter("pid"));
    int fpid = Integer.parseInt(request.getParameter("fpid"));
    int sid = Integer.parseInt(request.getParameter("sid"));
    Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession();
    s.beginTransaction();//from  w ww  . j a  v a 2s . co m
    Product pro = (Product) s.load(Product.class, pid);
    if (pro.getFeaturedItems() != null && !pro.getFeaturedItems().isEmpty()) {
        pro.setFeaturedItems(pro.getFeaturedItems() + request.getParameter("fpid") + ",");
    } else {
        pro.setFeaturedItems(request.getParameter("fpid") + ",");
    }
    s.update(pro);
    s.getTransaction().commit();
    s.close();
    response.sendRedirect("edit_product.jsp?pid=" + pid + "&sid=" + sid);
}

From source file:com.certus.actions.ChooseSubCatAction.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getParameter("cat_id") != null && request.getParameter("pid") != null) {
        Session session = com.certus.connection.HibernateUtil.getSessionFactory().openSession();

        List<SubCategory> lst = session.createCriteria(com.certus.dbmodel.SubCategory.class, "Sub_cat")
                .createAlias("Sub_cat.category", "category")
                .add(Restrictions.eq("category.id", Integer.parseInt(request.getParameter("cat_id")))).list();
        Product pro = (Product) session.load(Product.class, Integer.parseInt(request.getParameter("pid")));

        String sCats = "";
        for (SubCategory cat : lst) {
            String s;//from   ww w.j a v  a 2 s.c  o  m
            if (pro.getSubCategory().getId() == cat.getId()) {
                s = " selected='selected'";
            } else {
                s = "";
            }
            sCats += "<option value='" + cat.getId() + "' " + s + ">"
                    + cat.getSubCategoryName().substring(0, 1).toUpperCase()
                    + cat.getSubCategoryName().substring(1) + "</option>";
        }
        session.close();
        response.getWriter().write(sCats);

    }
}