Reputation: 775
Recently while going through spring's mongotemplate they touched upon repositories (here). Say, for example, a CRUD repository, is it a repository made for all your CRUD operations? Could anyone explain this in more simple terms, what exactly is the puropse of a repository?
Upvotes: 0
Views: 87
Reputation: 308763
Persisting data is all about CRUD (Create/Read/Update/Delete), but you can use different technologies to implement these operations.
The link you provided happens to choose MongoDB, a populate NoSQL document database. Spring Data can also work with relational SQL databases, object databases, graph databases, etc.
The beauty of designing to an interface, and the true power of Spring, is that you can separate what you need accomplished from the details of how it's done. Spring dependency injection makes it easy to swap in different implementations so you don't have to be bound too tightly to your choice.
Here's a simple generic DAO interface with CRUD operations:
package persistence;
public interface GenericDao<K, V> {
List<V> find();
V find(K id);
K save(V value);
void update(V value);
void delete(V value);
}
You could have a HibernateGenericDao:
package persistence;
public class HibernateGenericDao implements GenericDao<K, V> {
// implement methods using Hibernate here.
}
Upvotes: 2