use of br.com.fiap.jpa.exception.CommitException in project 2TDSS-Digital by thiagoyama.
the class SelecaoResource method cadastrar.
// Cadastrar
@POST
// Recebe JSON
@Consumes(MediaType.APPLICATION_JSON)
public Response cadastrar(Selecao selecao, @Context UriInfo uri) {
try {
dao.inserir(selecao);
dao.commit();
} catch (CommitException e) {
e.printStackTrace();
// Retorna o Status Code 500 do HTTP
return Response.serverError().build();
}
// Recupera a URL atual
UriBuilder b = uri.getAbsolutePathBuilder();
// Adiciona o c�digo da sele��o na URL
b.path(String.valueOf(selecao.getCodigo()));
// Retorna Status 201 com a URL para acessar a sele��o
return Response.created(b.build()).build();
}
use of br.com.fiap.jpa.exception.CommitException in project 2TDSS-Digital by thiagoyama.
the class GenericDAOImpl method commit.
@Override
public void commit() throws CommitException {
try {
em.getTransaction().begin();
em.getTransaction().commit();
} catch (Exception e) {
if (em.getTransaction().isActive())
em.getTransaction().rollback();
e.printStackTrace();
throw new CommitException("Erro ao gravar");
}
}
Aggregations