Search in sources :

Example 16 with Product

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);
}
Also used : Product(com.ncedu.fooddelivery.api.v1.entities.Product)

Example 17 with 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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Product(entities.Product)

Example 18 with Product

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Product(entities.Product)

Example 19 with Product

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Product(entities.Product)

Example 20 with Product

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Product(entities.Product)

Aggregations

Product (com.ncedu.fooddelivery.api.v1.entities.Product)17 Test (org.junit.jupiter.api.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 WarehouseInfoDTO (com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO)10 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)9 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)9 Product (entities.Product)9 ProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)8 SearchProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 Point (com.vividsolutions.jts.geom.Point)5 Pageable (org.springframework.data.domain.Pageable)5 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 CoordsDTO (com.ncedu.fooddelivery.api.v1.dto.CoordsDTO)3 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)3 PageImpl (org.springframework.data.domain.PageImpl)3 com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO (com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO)2 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)2 ProductAvailabilityEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.ProductAvailabilityEx)2