I am working on a JAX-RS project, with a DAO layer. I am not sure about which architecture to follow.
For example, let's say we have a ProductDAOImpl
class that implements a ProductDAO
interface, and a ProductRS
class as the entrypoint for the products REST service.
Question 1
Where should the ProductDAO
(actually ProductDAOImpl
) instance be created?
Options:
A) In each method of the ProductRS
class that needs access to the product?
B) As a member of the ProductRS
class?
(Can this option introduce data races? Not sure how the container handles the REST services classes - Possibly related to question 2 below.)
Question 2
Should I use annotations for JAX-RS classes, such as @Stateless
?
Question 3
What are the best practices for the architecture and class relationship in a JAX-RS application with a DAO layer and possibly a Service layer?
(Any links to study for this topic are more than welcome.)
Question 4
Should the DAO implementation classes provide static methods? (as seen here)
Implementation specific details
Using Jersey implementation of JAX-RS with Glassfish server and a DAO layer with JDBC access to the data source.