BAEL-2803 (#6640)
* added sample code for eval article * BAEL-2803 Sample Code * updated tests, repo method names * moved sources for BAEL-2803 here * removed dependencies introduced by BAEL-2803 * re-added sources * moved code to new module * removed eval article code
This commit is contained in:
parent
8a9cfe80e9
commit
c9211557bd
@ -0,0 +1,48 @@
|
|||||||
|
package com.baeldung.exists;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author paullatzelsperger
|
||||||
|
* @since 2019-03-20
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class Car {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private int id;
|
||||||
|
private Integer power;
|
||||||
|
private String model;
|
||||||
|
|
||||||
|
Car() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Car(int power, String model) {
|
||||||
|
this.power = power;
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPower() {
|
||||||
|
return power;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPower(Integer power) {
|
||||||
|
this.power = power;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel(String model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.exists;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author paullatzelsperger
|
||||||
|
* @since 2019-03-20
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface CarRepository extends JpaRepository<Car, Integer> {
|
||||||
|
|
||||||
|
boolean existsCarByPower(int power);
|
||||||
|
|
||||||
|
boolean existsCarByModel(String model);
|
||||||
|
|
||||||
|
@Query("select case when count(c)> 0 then true else false end from Car c where c.model = :model")
|
||||||
|
boolean existsCarExactCustomQuery(@Param("model") String model);
|
||||||
|
|
||||||
|
@Query("select case when count(c)> 0 then true else false end from Car c where lower(c.model) like lower(:model)")
|
||||||
|
boolean existsCarLikeCustomQuery(@Param("model") String model);
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
package com.baeldung.exists;
|
package com.baeldung.exists;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import com.baeldung.Application;
|
||||||
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -13,13 +11,12 @@ import org.springframework.data.domain.Example;
|
|||||||
import org.springframework.data.domain.ExampleMatcher;
|
import org.springframework.data.domain.ExampleMatcher;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import com.baeldung.boot.Application;
|
|
||||||
import com.baeldung.boot.domain.Car;
|
|
||||||
import com.baeldung.boot.repository.CarRepository;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = {Application.class})
|
@SpringBootTest(classes = {Application.class})
|
||||||
public class CarRepositoryIntegrationTest {
|
public class CarRepositoryIntegrationTest {
|
Loading…
x
Reference in New Issue
Block a user