Commit 3df0d996 by Patryk Czarnik

Wydzielenie interfejsu repository

parent f745cf05
......@@ -3,27 +3,12 @@ package sklep.repository;
import java.util.List;
import java.util.Optional;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import sklep.model.Product;
@Repository
public class ProductRepository {
@Autowired
private EntityManager em;
public interface ProductRepository {
public List<Product> findAll() {
TypedQuery<Product> query = em.createNamedQuery("Product.findAll", Product.class);
return query.getResultList();
}
List<Product> findAll();
public Optional<Product> findById(int productId) {
Product product = em.find(Product.class, productId);
return Optional.ofNullable(product);
}
Optional<Product> findById(int productId);
}
\ No newline at end of file
package sklep.repository;
import java.util.List;
import java.util.Optional;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import sklep.model.Product;
@Repository
public class ProductRepositoryImpl implements ProductRepository {
@Autowired
private EntityManager em;
@Override
public List<Product> findAll() {
TypedQuery<Product> query = em.createNamedQuery("Product.findAll", Product.class);
return query.getResultList();
}
@Override
public Optional<Product> findById(int productId) {
Product product = em.find(Product.class, productId);
return Optional.ofNullable(product);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment