Example usage for org.hibernate Session flush

List of usage examples for org.hibernate Session flush

Introduction

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

Prototype

void flush() throws HibernateException;

Source Link

Document

Force this session to flush.

Usage

From source file:com.bakeryfactory.vendas.servidor.VendaFreteGridAction.java

License:Open Source License

private Response delete(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from   w  w  w .j  av  a  2 s  . co  m*/
        GridParams pars = (GridParams) inputPar;
        ArrayList persistentObjects = (ArrayList) pars.getOtherGridParams().get("persistentObjects");

        VendaFreteVO vo = null;

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        for (int i = 0; i < persistentObjects.size(); i++) {
            vo = (VendaFreteVO) persistentObjects.get(i);
            session.delete(vo);
            session.flush();
        }
        session.getTransaction().commit();
        return new VOListResponse(persistentObjects, false, persistentObjects.size());
    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
        }
    }
}

From source file:com.bakeryfactory.vendas.servidor.VendaGridAction.java

License:Open Source License

private Response delete(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/* w w  w  .j  av a 2s.c om*/
        GridParams pars = (GridParams) inputPar;
        ArrayList persistentObjects = (ArrayList) pars.getOtherGridParams().get("persistentObjects");

        VendaCabecalhoVO vo = null;

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        for (int i = 0; i < persistentObjects.size(); i++) {
            vo = (VendaCabecalhoVO) persistentObjects.get(i);
            session.delete(vo);
            session.flush();
        }
        session.getTransaction().commit();
        return new VOListResponse(persistentObjects, false, persistentObjects.size());
    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
        }
    }
}

From source file:com.bakeryfactory.vendas.servidor.VendaOrcamentoGridAction.java

License:Open Source License

private Response delete(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from  ww  w. j av  a2s  .  c o  m*/
        GridParams pars = (GridParams) inputPar;
        ArrayList persistentObjects = (ArrayList) pars.getOtherGridParams().get("persistentObjects");

        VendaOrcamentoCabecalhoVO vo = null;

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        for (int i = 0; i < persistentObjects.size(); i++) {
            vo = (VendaOrcamentoCabecalhoVO) persistentObjects.get(i);
            session.delete(vo);
            session.flush();
        }
        session.getTransaction().commit();
        return new VOListResponse(persistentObjects, false, persistentObjects.size());
    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
        }
    }
}

From source file:com.bakeryfactory.vendas.servidor.VendaRomaneioEntregaGridAction.java

License:Open Source License

private Response delete(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from w  ww .ja va2  s.  c  om*/
        GridParams pars = (GridParams) inputPar;
        ArrayList persistentObjects = (ArrayList) pars.getOtherGridParams().get("persistentObjects");

        VendaRomaneioEntregaVO vo = null;

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        for (int i = 0; i < persistentObjects.size(); i++) {
            vo = (VendaRomaneioEntregaVO) persistentObjects.get(i);
            session.delete(vo);
            session.flush();
        }
        session.getTransaction().commit();
        return new VOListResponse(persistentObjects, false, persistentObjects.size());
    } catch (Exception ex) {
        if (session != null) {
            session.getTransaction().rollback();
        }
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
        }
    }
}

From source file:com.balero.models.BlogDAO.java

License:Open Source License

@Transactional
public void addPost(String postitle, String postbody, String postslug, Locale postlocale, String postauthor,
        String poststatus) {/*from  w w w  .  j  a  v  a  2  s  .  c o  m*/
    Session session = sessionFactory.openSession();
    Blog Blog = new Blog();
    Blog.setPosttitle(postitle);
    Blog.setPostbody(postbody);
    Blog.setPostslug(postslug);
    Blog.setPostlocale(postlocale.toString());
    Blog.setPostauthor(postauthor);
    Blog.setPoststatus(poststatus);
    session.save(Blog);
    session.flush();
    session.close();
}

From source file:com.balero.models.BlogDAO.java

License:Open Source License

@Transactional
public void updatePost(int id, String posttitle, String postbody, String postslug, String postlocale,
        String postauhtor, String poststatus) {
    Session session = sessionFactory.openSession();
    Blog Blog = new Blog();
    Blog.setId(id);//from   w w w.j a v a2s .com
    Blog.setPosttitle(posttitle);
    Blog.setPostbody(postbody);
    Blog.setPostslug(postslug);
    Blog.setPostlocale(postlocale);
    Blog.setPostauthor(postauhtor);
    Blog.setPoststatus(poststatus);
    session.update(Blog);
    session.flush();
    session.close();
}

From source file:com.balero.models.BlogDAO.java

License:Open Source License

@Transactional
public void deletePost(int id) {
    Session session = sessionFactory.openSession();
    Blog Blog = new Blog();
    Blog.setId(id);/*from   www .  jav a 2  s . c  om*/
    session.delete(Blog);
    session.flush();
    session.close();
}

From source file:com.balero.models.BlogDAO.java

License:Open Source License

@Transactional
public void make(Locale locale) {
    Session session = sessionFactory.getCurrentSession();
    Blog Blog = new Blog();
    Blog.setId(1);/*from   w  w w  . jav a 2 s.com*/
    Blog.setPosttitle("<h3>Lorem ipsum</h3>\n" + "\n"
            + "<p>Lorem Ipsum is text that is commonly used in graphic design typefaces demonstrations or draft design to test the visual design before inserting the final text.</p>\n"
            + "\n"
            + "<p>Although currently has no sources to justify tesis hip, professor of classical philology Richard McClintock says its use dates back to the early printers XVI.1 century Its use in some text editors well known in today has given the new popularity lorem ipsum.</p>\n"
            + "\n"
            + "<p>The text itself no sense, although it is not completely random, but derives from a text by Cicero in Latin language, whose words have been removed them syllables or letters. The meaning of the text does not matter, since it is just a test demostracino,</p>\n");
    Blog.setPostbody("Read more content...");
    Blog.setPostslug("welcome-test-post");
    Blog.setPostlocale(locale.toString());
    Blog.setPostauthor("admin");
    Blog.setPoststatus("published");
    session.save(Blog);
    session.flush();
}

From source file:com.balero.models.CommentsDAO.java

License:Open Source License

@Transactional
public void addComment(String commentname, String commentbody, int commentpostid) {
    Session session = sessionFactory.openSession();
    Comments comments = new Comments();
    comments.setCommentname(commentname);
    comments.setCommentbody(commentbody);
    comments.setCommentdate(new Date());
    comments.setCommentpostid(commentpostid);
    session.save(comments);//from w w w  . j  a v a  2  s . c  o  m
    session.flush();
    session.close();
}

From source file:com.balero.models.CommentsDAO.java

License:Open Source License

@Transactional
public void deleteComment(int id) {
    Session session = sessionFactory.openSession();
    Comments comments = new Comments();
    comments.setId(id);//from w  w  w  .  j a v  a2s . c o  m
    session.delete(comments);
    session.flush();
    session.close();
}