* 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:
Paul Latzelsperger 2019-04-02 21:13:24 +02:00 committed by maibin
parent 8a9cfe80e9
commit c9211557bd
3 changed files with 76 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -1,8 +1,6 @@
package com.baeldung.exists;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase;
import com.baeldung.Application;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -13,13 +11,12 @@ import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
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.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {Application.class})
public class CarRepositoryIntegrationTest {