use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceImpl method deleteProduct.
@Override
public void deleteProduct(Long id) {
Product product = getProductById(id);
productRepo.delete(product);
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project youtubechannel by lspil.
the class Example2 method main.
public static void main(String[] args) {
var emf = Persistence.createEntityManagerFactory("my-persistence-unit");
var em = emf.createEntityManager();
em.getTransaction().begin();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Product> query = builder.createQuery(Product.class);
Root<Product> product = query.from(Product.class);
query.select(product);
TypedQuery<Product> tq = em.createQuery(query);
List<Product> result = tq.getResultList();
result.forEach(System.out::println);
em.getTransaction().commit();
em.close();
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project youtubechannel by lspil.
the class Example4 method buildProductCriteriaQuery.
public static CriteriaQuery<Product> buildProductCriteriaQuery(EntityManager em) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Product> query = builder.createQuery(Product.class);
var param = builder.parameter(Double.class, "price");
Root<Product> product = query.from(Product.class);
query.select(product).where(builder.greaterThan(product.get("price"), param));
return query;
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project youtubechannel by lspil.
the class Example3 method main.
public static void main(String[] args) {
var emf = Persistence.createEntityManagerFactory("my-persistence-unit");
var em = emf.createEntityManager();
em.getTransaction().begin();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Product> query = builder.createQuery(Product.class);
Root<Product> product = query.from(Product.class);
query.select(query.from(Product.class));
TypedQuery<Product> tq = em.createQuery(query);
List<Product> result = tq.getResultList();
result.forEach(System.out::println);
em.getTransaction().commit();
em.close();
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project youtubechannel by lspil.
the class Example4 method findProductsByPrice.
// WRONG!
public List<Product> findProductsByPrice(EntityManager em, double price) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Product> query = builder.createQuery(Product.class);
Root<Product> product = query.from(Product.class);
query.select(product).where(builder.greaterThan(product.get("price"), price));
TypedQuery<Product> tq = em.createQuery(query);
List<Product> result = tq.getResultList();
return result;
}
Aggregations