Creative crypter
Creative crypter

Reputation: 1496

Java - Spring data access object implementation

In my current spring setup i would like to implement a slightly different architecture, here is my setup:

I have a "base" DAO interface, which lists all CRUD operations:

public interface BaseDao {

    public boolean create(Object obj);

    public List<Object> read();

    public boolean update(Object obj);

    public boolean delete(Object obj);

}

Next i have "specific" DAO interface, which extends from the "base" one:

public interface ArticleDao extends BaseDao {

    public List<Article> getArticlesByAttribute(String attribute);

}

And finally, the Repository, which implements the interface:

public class ArticleDaoImpl implements ArticleDao {

    public boolean create(Article article) {
        // code
    }

    public List<Article> read() {
        // code
    }

    public boolean update(Article article) {
        // code
    }

    public boolean delete(Article article) {
        // code
    }

    public List<Article> getArticlesByAttribute(String attribute) {
        // code
    }
}

So the idea is simple:

I want every Repository to implement all crud operations + "the methods from the specific dao-interface"

But i get the following error:

ArticleDaoImpl is not abstract and does not override
abstract method delete(java.lang.Object) in BaseDao

etc..

So this is probably because i defined Object as a parameter in the interface and "Article" as a parameter in the actual implementation..

Anybody got the idea how i can follow this pattern correctly? Should i consider working with generics?

Thanks and Greetings

Upvotes: 0

Views: 796

Answers (1)

Rafal G.
Rafal G.

Reputation: 4432

No. You should work with Spring Data JPA/MongoDB etc. It will make MOST of your boilerplate code go away. Seriously - forget about DAO and go with Spring Data JPA: https://spring.io/guides/gs/accessing-data-jpa/

Upvotes: 2

Related Questions