[STYLE] repositoryの無駄な改行やスペースなどの削除

This commit is contained in:
s-choi
2026-09-10 15:48:32 +09:00
parent 178690c7b9
commit d2c78b12aa
3 changed files with 55 additions and 101 deletions

View File

@@ -1,50 +1,31 @@
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.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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
public interface DepartmentRepository extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> {
public interface DepartmentRepository
extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> {
static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return idDepartment == null ? null
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.equal(root.get("idDepartment"), idDepartment);
}
static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return idDepartment == null ?
null :
// 戻り値の型 Specification<DepartmentEntity> にキャスト
(Specification<DepartmentEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
// を作成している
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idDepartment"), idDepartment);
}
static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ? null
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.like(root.get("nmDepartment"), nmDepartment);
}
static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ?
null :
(Specification<DepartmentEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), nmDepartment);
}
static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ?
null :
(Specification<DepartmentEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), "%" + nmDepartment + "%");
}
static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ? null
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.like(root.get("nmDepartment"), "%" + nmDepartment + "%");
}
}

View File

@@ -1,61 +1,42 @@
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.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
/**
* ワンポイント情報(ここで登場する関数型インターフェース Specification について解説します)
* Specification:
* 関数型インターフェースです。
* JPAの一部として提供されていて、エンティティの情報を元に動的にクエリを生成し、DBからデータを取得します。
* 使い方:
* toPredicate をOverrideして使います。
* パラメータ:
* Root<T>:ルートエンティティを指します。<T>に指定したエンティティ(今回はDepartmentEntity)を用いてメンバにアクセスします。
* CriteriaQuery<\?>:サブクエリを作成する際に使用します。※今回は使用しません
* CriteriaBuilder:条件式(Where句以降の条件)の部分のクエリを作るためのビルダーです。
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。
*/
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
@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) {
return idEmployee == null ?
null :
// 戻り値の型 Specification<EmployeeDepartmentEntity> にキャスト
(Specification<EmployeeDepartmentEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idEmployee' = idEmployee(変数)"
// を作成している
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idEmployee"), idEmployee);
}
static Specification<EmployeeDepartmentEntity> idEmployeeEqual(Integer idEmployee) {
return idEmployee == null ? null
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.equal(root.get("idEmployee"), idEmployee);
}
static Specification<EmployeeDepartmentEntity> nmEmployeeEqual(String nmEmployee) {
return (nmEmployee == null || nmEmployee.isEmpty()) ?
null :
(Specification<EmployeeDepartmentEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmEmployee"), "%" + nmEmployee + "%");
}
static Specification<EmployeeDepartmentEntity> nmEmployeeEqual(String nmEmployee) {
return (nmEmployee == null || nmEmployee.isEmpty()) ? null
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.like(root.get("nmEmployee"), "%" + nmEmployee + "%");
}
static Specification<EmployeeDepartmentEntity> knEmployeeEqual(String knEmployee) {
return (knEmployee == null || knEmployee.isEmpty()) ?
null :
(Specification<EmployeeDepartmentEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("knEmployee"), "%" + knEmployee + "%");
}
static Specification<EmployeeDepartmentEntity> knEmployeeEqual(String knEmployee) {
return (knEmployee == null || knEmployee.isEmpty()) ? null
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.like(root.get("knEmployee"), "%" + knEmployee + "%");
}
static Specification<EmployeeDepartmentEntity> mailAddressEqual(String mailAddress) {
return (mailAddress == null || mailAddress.isEmpty()) ?
null :
(Specification<EmployeeDepartmentEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("mailAddress"), "%" + mailAddress + "%");
}
static Specification<EmployeeDepartmentEntity> mailAddressEqual(String mailAddress) {
return (mailAddress == null || mailAddress.isEmpty()) ? null
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.like(root.get("mailAddress"), "%" + mailAddress + "%");
}
static Specification<EmployeeDepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return (root, query, criteriaBuilder) ->
idDepartment == null ? null :
criteriaBuilder.equal(root.join("department").get("idDepartment"), idDepartment);
}
static Specification<EmployeeDepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return (root, query, criteriaBuilder) -> idDepartment == null ? null
: criteriaBuilder.equal(root.join("department").get("idDepartment"), idDepartment);
}
}

View File

@@ -1,28 +1,20 @@
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.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.EmployeeEntity;
@Repository
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);
}