[STYLE] repositoryの無駄な改行やスペースなどの削除
This commit is contained in:
@@ -1,50 +1,31 @@
|
|||||||
package com.example.rhizome.app.infra.repository;
|
package com.example.rhizome.app.infra.repository;
|
||||||
|
|
||||||
import com.example.rhizome.app.infra.entity.DepartmentEntity;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.example.rhizome.app.infra.entity.DepartmentEntity;
|
||||||
|
|
||||||
/**
|
|
||||||
* Specification:
|
|
||||||
* 関数型インターフェースです。
|
|
||||||
* JPAの一部として提供されていて、エンティティの情報を元に動的にクエリを生成し、DBからデータを取得します。
|
|
||||||
* 使い方:
|
|
||||||
* toPredicate をOverrideして使います。
|
|
||||||
* パラメータ:
|
|
||||||
* Root<T>:ルートエンティティを指します。<T>に指定したエンティティ(今回はDepartmentEntity)を用いてメンバにアクセスします。
|
|
||||||
* CriteriaQuery<\?>:サブクエリを作成する際に使用します。※今回は使用しません
|
|
||||||
* CriteriaBuilder:条件式(Where句以降の条件)の部分のクエリを作るためのビルダーです。
|
|
||||||
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。
|
|
||||||
*/
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface DepartmentRepository extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> {
|
public interface DepartmentRepository
|
||||||
|
extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> {
|
||||||
|
|
||||||
static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) {
|
static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) {
|
||||||
return idDepartment == null ?
|
return idDepartment == null ? null
|
||||||
null :
|
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
|
||||||
// 戻り値の型 Specification<DepartmentEntity> にキャスト
|
.equal(root.get("idDepartment"), idDepartment);
|
||||||
(Specification<DepartmentEntity>)
|
|
||||||
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
|
|
||||||
// を作成している
|
|
||||||
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idDepartment"), idDepartment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) {
|
static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) {
|
||||||
return (nmDepartment == null || nmDepartment.isEmpty()) ?
|
return (nmDepartment == null || nmDepartment.isEmpty()) ? null
|
||||||
null :
|
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
|
||||||
(Specification<DepartmentEntity>)
|
.like(root.get("nmDepartment"), nmDepartment);
|
||||||
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), nmDepartment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) {
|
static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) {
|
||||||
return (nmDepartment == null || nmDepartment.isEmpty()) ?
|
return (nmDepartment == null || nmDepartment.isEmpty()) ? null
|
||||||
null :
|
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
|
||||||
(Specification<DepartmentEntity>)
|
.like(root.get("nmDepartment"), "%" + nmDepartment + "%");
|
||||||
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), "%" + nmDepartment + "%");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +1,42 @@
|
|||||||
package com.example.rhizome.app.infra.repository;
|
package com.example.rhizome.app.infra.repository;
|
||||||
|
|
||||||
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
/**
|
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
|
||||||
* ワンポイント情報(ここで登場する関数型インターフェース Specification について解説します)
|
|
||||||
* Specification:
|
|
||||||
* 関数型インターフェースです。
|
|
||||||
* JPAの一部として提供されていて、エンティティの情報を元に動的にクエリを生成し、DBからデータを取得します。
|
|
||||||
* 使い方:
|
|
||||||
* toPredicate をOverrideして使います。
|
|
||||||
* パラメータ:
|
|
||||||
* Root<T>:ルートエンティティを指します。<T>に指定したエンティティ(今回はDepartmentEntity)を用いてメンバにアクセスします。
|
|
||||||
* CriteriaQuery<\?>:サブクエリを作成する際に使用します。※今回は使用しません
|
|
||||||
* CriteriaBuilder:条件式(Where句以降の条件)の部分のクエリを作るためのビルダーです。
|
|
||||||
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。
|
|
||||||
*/
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface EmployeeInfoRepository extends JpaRepository<EmployeeDepartmentEntity, Integer>, JpaSpecificationExecutor<EmployeeDepartmentEntity> {
|
public interface EmployeeInfoRepository
|
||||||
|
extends JpaRepository<EmployeeDepartmentEntity, Integer>, JpaSpecificationExecutor<EmployeeDepartmentEntity> {
|
||||||
|
|
||||||
static Specification<EmployeeDepartmentEntity> idEmployeeEqual(Integer idEmployee) {
|
static Specification<EmployeeDepartmentEntity> idEmployeeEqual(Integer idEmployee) {
|
||||||
return idEmployee == null ?
|
return idEmployee == null ? null
|
||||||
null :
|
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
|
||||||
// 戻り値の型 Specification<EmployeeDepartmentEntity> にキャスト
|
.equal(root.get("idEmployee"), idEmployee);
|
||||||
(Specification<EmployeeDepartmentEntity>)
|
|
||||||
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idEmployee' = idEmployee(変数)"
|
|
||||||
// を作成している
|
|
||||||
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idEmployee"), idEmployee);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Specification<EmployeeDepartmentEntity> nmEmployeeEqual(String nmEmployee) {
|
static Specification<EmployeeDepartmentEntity> nmEmployeeEqual(String nmEmployee) {
|
||||||
return (nmEmployee == null || nmEmployee.isEmpty()) ?
|
return (nmEmployee == null || nmEmployee.isEmpty()) ? null
|
||||||
null :
|
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
|
||||||
(Specification<EmployeeDepartmentEntity>)
|
.like(root.get("nmEmployee"), "%" + nmEmployee + "%");
|
||||||
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmEmployee"), "%" + nmEmployee + "%");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Specification<EmployeeDepartmentEntity> knEmployeeEqual(String knEmployee) {
|
static Specification<EmployeeDepartmentEntity> knEmployeeEqual(String knEmployee) {
|
||||||
return (knEmployee == null || knEmployee.isEmpty()) ?
|
return (knEmployee == null || knEmployee.isEmpty()) ? null
|
||||||
null :
|
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
|
||||||
(Specification<EmployeeDepartmentEntity>)
|
.like(root.get("knEmployee"), "%" + knEmployee + "%");
|
||||||
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("knEmployee"), "%" + knEmployee + "%");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Specification<EmployeeDepartmentEntity> mailAddressEqual(String mailAddress) {
|
static Specification<EmployeeDepartmentEntity> mailAddressEqual(String mailAddress) {
|
||||||
return (mailAddress == null || mailAddress.isEmpty()) ?
|
return (mailAddress == null || mailAddress.isEmpty()) ? null
|
||||||
null :
|
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
|
||||||
(Specification<EmployeeDepartmentEntity>)
|
.like(root.get("mailAddress"), "%" + mailAddress + "%");
|
||||||
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("mailAddress"), "%" + mailAddress + "%");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Specification<EmployeeDepartmentEntity> idDepartmentEqual(Integer idDepartment) {
|
static Specification<EmployeeDepartmentEntity> idDepartmentEqual(Integer idDepartment) {
|
||||||
return (root, query, criteriaBuilder) ->
|
return (root, query, criteriaBuilder) -> idDepartment == null ? null
|
||||||
idDepartment == null ? null :
|
: criteriaBuilder.equal(root.join("department").get("idDepartment"), idDepartment);
|
||||||
criteriaBuilder.equal(root.join("department").get("idDepartment"), idDepartment);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,20 @@
|
|||||||
package com.example.rhizome.app.infra.repository;
|
package com.example.rhizome.app.infra.repository;
|
||||||
|
|
||||||
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Integer> {
|
public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Integer> {
|
||||||
Optional<EmployeeEntity> findByMailAddressAndPassword(String mailAddress, String password);
|
Optional<EmployeeEntity> findByMailAddressAndPassword(String mailAddress, String password);
|
||||||
|
|
||||||
/**
|
|
||||||
* メールアドレスで検索
|
|
||||||
**/
|
|
||||||
Optional<EmployeeEntity> findByMailAddress(String mail);
|
Optional<EmployeeEntity> findByMailAddress(String mail);
|
||||||
|
|
||||||
/**
|
|
||||||
* IDで検索
|
|
||||||
**/
|
|
||||||
Optional<EmployeeEntity> findByIdEmployee(Integer idEmployee);
|
Optional<EmployeeEntity> findByIdEmployee(Integer idEmployee);
|
||||||
|
|
||||||
/**
|
|
||||||
* IDで検索
|
|
||||||
**/
|
|
||||||
List<EmployeeEntity> findByIdDepartment(Integer idDepartment);
|
List<EmployeeEntity> findByIdDepartment(Integer idDepartment);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user