Example usage for org.hibernate Session update

List of usage examples for org.hibernate Session update

Introduction

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

Prototype

void update(Object object);

Source Link

Document

Update the persistent instance with the identifier of the given detached instance.

Usage

From source file:com.bakeryfactory.calendarioproducao.servidor.AgendaCategoriaCompromissoDetalheAction.java

public Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//from  w  w  w .jav  a 2 s. c  om
        Object[] pars = (Object[]) inputPar;
        AgendaCategoriaCompromissoVO agendaCategoriaCompromisso = (AgendaCategoriaCompromissoVO) pars[2];

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

        session.update(agendaCategoriaCompromisso);

        session.getTransaction().commit();

        return new VOResponse(agendaCategoriaCompromisso);
    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.calendarioproducao.servidor.AgendaCompromissoDetalheAction.java

public Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from   w w  w .  j a  va  2 s .  c  om*/
        Object[] pars = (Object[]) inputPar;
        AgendaCompromissoVO agendaCompromisso = (AgendaCompromissoVO) pars[2];
        ProducaoSalaEventoVO reuniaoSalaEvento = (ProducaoSalaEventoVO) pars[3];

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

        incluiCompromissoConvidado(agendaCompromisso, session);

        for (AgendaCompromissoConvidadoVO c : agendaCompromisso.getListaAgendaCompromissoConvidado()) {
            c.setAgendaCompromisso(agendaCompromisso);
        }

        session.update(agendaCompromisso);

        session.update(reuniaoSalaEvento);

        session.getTransaction().commit();

        return new VOResponse(agendaCompromisso);
    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.calendarioproducao.servidor.ProducaoSalaDetalheAction.java

public Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*  w  w w  .ja v a  2  s  .co m*/
        Object[] pars = (Object[]) inputPar;
        ProducaoSalaVO producaoSala = (ProducaoSalaVO) pars[2];

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

        session.update(producaoSala);

        session.getTransaction().commit();

        return new VOResponse(producaoSala);
    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.pcp.servidor.PcpInstrucaoDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//  w ww .  ja v a2  s  . c  om
        Object[] pars = (Object[]) inputPar;
        PcpInstrucaoVO pcpInstrucao = (PcpInstrucaoVO) pars[2];

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

        session.update(pcpInstrucao);

        session.getTransaction().commit();

        return new VOResponse(pcpInstrucao);

    } 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) {
            ex1.printStackTrace();
        }
    }
}

From source file:com.bakeryfactory.pcp.servidor.PcpOpCabecalhoDetalheAction.java

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from  w w w.j a v  a  2 s .  co m*/
        Object[] pars = (Object[]) inputPar;
        PcpOpCabecalhoVO pcpOpCabecalho = (PcpOpCabecalhoVO) pars[2];
        List<PcpOpDetalheVO> detalhe = (Vector) pars[3];
        List<PcpInstrucaoOpVO> pcpInstrucao = (Vector) pars[4];

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

        saveOrUpdatePcpDetalhe(detalhe, pcpOpCabecalho, session);

        saveOrUpdatePcpInstrucao(pcpInstrucao, pcpOpCabecalho, session);

        session.getTransaction().commit();

        return new VOResponse(pcpOpCabecalho);

    } 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) {
            ex1.printStackTrace();
        }
    }
}

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

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {// w  ww  .j  ava 2s. co m
        Object[] pars = (Object[]) inputPar;
        NotaFiscalTipoVO notaFiscalTipo = (NotaFiscalTipoVO) pars[2];

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

        session.update(notaFiscalTipo);

        session.getTransaction().commit();

        return new VOResponse(notaFiscalTipo);

    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

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

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from  w  w  w.ja  va  2 s.com*/
        Object[] pars = (Object[]) inputPar;
        VendaCondicoesPagamentoVO vendaCondicoesPagamento = (VendaCondicoesPagamentoVO) pars[2];
        List<VendaCondicoesParcelaVO> parcelas = (Vector) pars[3];

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

        session.update(vendaCondicoesPagamento);

        queryExcluir(parcelas, vendaCondicoesPagamento, session);

        session.getTransaction().commit();

        return new VOResponse(vendaCondicoesPagamento);

    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

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

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {/*from w w  w.j  av  a2s  .c  o m*/
        Object[] pars = (Object[]) inputPar;
        VendaCabecalhoVO vendaCabecalho = (VendaCabecalhoVO) pars[2];
        List<VendaDetalheVO> orcamentoDetalhe = (Vector) pars[3];

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

        if (vendaCabecalho.getVendaOrcamentoCabecalho().getId() == null) {
            vendaCabecalho.setVendaOrcamentoCabecalho(null);
        }

        if (vendaCabecalho.getTransportadora().getId() == null) {
            vendaCabecalho.setTransportadora(null);
        }

        session.update(vendaCabecalho);

        String sqlExcluir = "delete from VENDA_DETALHE where ID not in (0";
        for (int i = 0; i < orcamentoDetalhe.size(); i++) {
            orcamentoDetalhe.get(i).setVendaCabecalho(vendaCabecalho);
            session.saveOrUpdate(orcamentoDetalhe.get(i));
            sqlExcluir += "," + orcamentoDetalhe.get(i).getId();
        }
        sqlExcluir += ") and ID_VENDA_CABECALHO = :id";
        Query query = session.createSQLQuery(sqlExcluir);
        query.setInteger("id", vendaCabecalho.getId());
        query.executeUpdate();

        Criteria criteria = session.createCriteria(VendaComissaoVO.class);
        criteria.add(Restrictions.eq("vendaCabecalho", vendaCabecalho));
        VendaComissaoVO comissao = (VendaComissaoVO) criteria.uniqueResult();

        comissao.setVendedor(vendaCabecalho.getVendedor());
        if (vendaCabecalho.getValorDesconto() != null) {
            comissao.setValorVenda(
                    vendaCabecalho.getValorSubtotal().subtract(vendaCabecalho.getValorDesconto()));
        } else {
            comissao.setValorVenda(vendaCabecalho.getValorSubtotal());
        }
        comissao.setTipoContabil("C");
        comissao.setValorComissao(vendaCabecalho.getValorComissao());
        comissao.setSituacao("A");
        comissao.setDataLancamento(new Date());

        session.update(comissao);

        session.getTransaction().commit();

        return new VOResponse(vendaCabecalho);
    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}

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

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//from  w ww  . j  a v a2s.  c  o m
        Object[] pars = (Object[]) inputPar;
        VendaFreteVO vendaFrete = (VendaFreteVO) pars[2];

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

        session.update(vendaFrete);

        session.getTransaction().commit();

        return new VOResponse(vendaFrete);

    } 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) {
            ex1.printStackTrace();
        }
    }
}

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

License:Open Source License

private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request,
        HttpServletResponse response, HttpSession userSession, ServletContext context) {
    Session session = null;
    try {//from   w w  w. j a  v a 2  s  . c om
        Object[] pars = (Object[]) inputPar;
        VendaOrcamentoCabecalhoVO vendaOrcamentoCabecalho = (VendaOrcamentoCabecalhoVO) pars[2];
        List<VendaOrcamentoDetalheVO> orcamentoDetalhe = (Vector) pars[3];

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

        if (vendaOrcamentoCabecalho.getTransportadora().getId() == null) {
            vendaOrcamentoCabecalho.setTransportadora(null);
        }

        session.update(vendaOrcamentoCabecalho);

        String sqlExcluir = "delete from VENDA_ORCAMENTO_DETALHE where ID not in (0";
        for (int i = 0; i < orcamentoDetalhe.size(); i++) {
            orcamentoDetalhe.get(i).setVendaOrcamentoCabecalho(vendaOrcamentoCabecalho);
            session.saveOrUpdate(orcamentoDetalhe.get(i));
            sqlExcluir += "," + orcamentoDetalhe.get(i).getId();
        }
        sqlExcluir += ") and ID_VENDA_ORCAMENTO_CABECALHO = :id";
        Query query = session.createSQLQuery(sqlExcluir);
        query.setInteger("id", vendaOrcamentoCabecalho.getId());
        query.executeUpdate();

        session.getTransaction().commit();

        return new VOResponse(vendaOrcamentoCabecalho);
    } catch (Exception ex) {
        ex.printStackTrace();
        if (session != null) {
            session.getTransaction().rollback();
        }
        return new ErrorResponse(ex.getMessage());
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
        }
    }
}