Skip to content

Commit

Permalink
Added named query.
Browse files Browse the repository at this point in the history
Changed EmployeeRepository.
Fixed enhanced test controller.
Updated Spring Version.
  • Loading branch information
gkatzioura committed Mar 2, 2017
1 parent 4c1ccfb commit afaeefa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
9 changes: 3 additions & 6 deletions SpringDataJPAIntegration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE")
}
}

apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'org.springframework.boot'

repositories {
mavenCentral()
}

dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.postgresql:postgresql:9.4-1206-jdbc42")
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.3.3.RELEASE")
compile("com.mchange:c3p0:0.9.5.2")
testCompile("junit:junit:4.11");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.gkatzioura.springdata.jpa.controller;

import com.gkatzioura.springdata.jpa.persistence.entity.Employee;
import com.gkatzioura.springdata.jpa.persistence.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.gkatzioura.springdata.jpa.persistence.entity.Employee;
import com.gkatzioura.springdata.jpa.persistence.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.List;

/**
* Created by gkatzioura on 6/2/16.
Expand All @@ -30,4 +30,9 @@ public List<Employee> getFiltered(String firstName,@RequestParam(defaultValue =
return employeeRepository.getFirstNamesLikeAndBonusBigger(firstName,bonusAmount);
}

@RequestMapping("/employee/lastnameLength")
public List<Employee> fetchByLength(Long length) {
return employeeRepository.fetchByLastNameLength(length);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
@Entity
@Table(name = "employee", schema="spring_data_jpa_example")
@NamedQuery(name = "Employee.fetchByLastNameLength",
query = "SELECT e FROM Employee e WHERE CHAR_LENGTH(e.lastname) =:length "
)
public class Employee {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import com.gkatzioura.springdata.jpa.persistence.entity.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* Created by gkatzioura on 6/2/16.
*/
@Repository
public interface EmployeeRepository extends JpaRepository<Employee,Long>, EmployeeRepositoryCustom {

List<Employee> fetchByLastNameLength(@Param("length") Long length);
}

0 comments on commit afaeefa

Please sign in to comment.