package com.github.daniel.shuy.ws.rs.jpa.crud;

import java.util.List;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * Extend this class to create a CRUD JAX-RS Repository Class.
 *
 * @param <E> The Entity Class type
 */
public interface ResourceCRUD<E extends EntityCRUD> {
    /**
     * Override this method to provide a Repository instance.
     * 
     * @return A Repository instance.
     */
    public abstract RepositoryCRUD<E> getRepository();

    @POST
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    @Transactional(rollbackOn = Exception.class)
    public default void create(E content) {
        getRepository().create(content);
    }

    @GET
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public default List<E> findAll() {
        return getRepository().findAll();
    }

    @GET
    @Path("{id}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public default E find(@PathParam("id") Long id) {
        return getRepository().find(id);
    }

    @GET
    @Path("{from}/{to}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public default List<E> findRange(@PathParam("from") Long from, @PathParam("to") Long to) {
        return getRepository().findRange(from, to);
    }

    @GET
    @Path("count")
    @Produces(MediaType.TEXT_PLAIN)
    public default String count() {
        return String.valueOf(getRepository().count());
    }
    
    @PUT
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    @Transactional(rollbackOn = Exception.class)
    public default void edit(E content) {
        getRepository().edit(content);
    }

    @DELETE
    @Path("{id}")
    @Transactional(rollbackOn = Exception.class)
    public default void remove(@PathParam("id") Long id) {
        getRepository().remove(id);
    }
}

@@ -474,17 +474,22 @@
 lic 
-interface
+abstract class
  Res
@@ -839,32 +839,24 @@
 %0A    public 
-default 
 void create(
@@ -1003,32 +1003,24 @@
 %0A    public 
-default 
 List%3CE%3E find
@@ -1185,24 +1185,16 @@
  public 
-default 
 E find(@
@@ -1384,24 +1384,16 @@
  public 
-default 
 List%3CE%3E 
@@ -1594,24 +1594,16 @@
  public 
-default 
 String c
@@ -1814,32 +1814,24 @@
 %0A    public 
-default 
 void edit(E 
@@ -1958,32 +1958,32 @@
 xception.class)%0A
+
     public defau
@@ -1981,16 +1981,8 @@
 lic 
-default 
 void

Change ResourceCRUD from an Interface to an Abstract Class