Search in sources :

Example 1 with CommitException

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();
}
Also used : CommitException(br.com.fiap.jpa.exception.CommitException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with CommitException

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");
    }
}
Also used : CommitException(br.com.fiap.jpa.exception.CommitException) KeyNotFoundException(br.com.fiap.jpa.exception.KeyNotFoundException) CommitException(br.com.fiap.jpa.exception.CommitException)

Aggregations

CommitException (br.com.fiap.jpa.exception.CommitException)2 KeyNotFoundException (br.com.fiap.jpa.exception.KeyNotFoundException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 UriBuilder (javax.ws.rs.core.UriBuilder)1