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

This commit is contained in:
s-choi
2026-09-10 15:47:37 +09:00
parent 8b44c7a7b6
commit 178690c7b9
3 changed files with 151 additions and 282 deletions

View File

@@ -1,25 +1,20 @@
/*
* Department.java
* 作成 IT-College 2016
*------------------------------------------------------------
* Copyright(c) Rhizome Inc. All Rights Reserved.
*/
package com.example.rhizome.app.infra.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.example.rhizome.app.domain.model.Department;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.List;
/**
* Department テーブルの Entity
*
* @author IT-College
*/
@Entity
@Table(name = "department")
@Data
@@ -27,46 +22,26 @@ import java.util.List;
@AllArgsConstructor
public class DepartmentEntity {
/**
* 部署ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_department", nullable = false)
private Integer idDepartment;
/**
* 部署名
*/
@Column(name = "nm_department", nullable = false)
private String nmDepartment;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_department", nullable = false)
private Integer idDepartment;
@Column(name = "nm_department", nullable = false)
private String nmDepartment;
/**
* DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。
*
* @param departmentEntityList department Table のリスト
* @return List<Department> リスト
*/
public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) {
public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) {
// Stream API を利用するとこうなります。
return departmentEntityList
.stream()
.map(departmentEntity -> new Department(
departmentEntity.getIdDepartment(),
departmentEntity.getNmDepartment()
)).toList();
}
return departmentEntityList
.stream()
.map(departmentEntity -> new Department(
departmentEntity.getIdDepartment(),
departmentEntity.getNmDepartment()))
.toList();
}
/**
* Department(BusinessLogic層依存型) から DepartmentEntity(DataAccess層依存)に変換します。
*
* @param department department モデルの値
* @return DepartmentEntity に変換したインスタンス
*/
public static DepartmentEntity convertFrom(Department department) {
return new DepartmentEntity(
department.getIdDepartment(),
department.getNmDepartment()
);
}
public static DepartmentEntity convertFrom(Department department) {
return new DepartmentEntity(
department.getIdDepartment(),
department.getNmDepartment());
}
}

View File

@@ -1,118 +1,86 @@
package com.example.rhizome.app.infra.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedEntityGraph;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import java.util.List;
/**
* Employee + Department の Join 情報を保持するEntity
*
* @author IT-College
*/
@Entity
@Table(name = "employee")
@Data
@AllArgsConstructor
@NoArgsConstructor
@NamedEntityGraph(
name = "employee_with_department",
includeAllAttributes = true
)
@NamedEntityGraph(name = "employee_with_department", includeAllAttributes = true)
public class EmployeeDepartmentEntity {
/**
* 社員ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_employee", nullable = false)
private Integer idEmployee;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_employee", nullable = false)
private Integer idEmployee;
/**
* 社員名
*/
@Column(name = "nm_employee", nullable = false)
private String nmEmployee;
@Column(name = "nm_employee", nullable = false)
private String nmEmployee;
/**
* 社員名カナ
*/
@Column(name = "kn_employee", nullable = false)
private String knEmployee;
@Column(name = "kn_employee", nullable = false)
private String knEmployee;
/**
* メールアドレス
*/
@Column(name = "mail_address", nullable = false)
private String mailAddress;
@Column(name = "mail_address", nullable = false)
private String mailAddress;
/**
* パスワード
*/
@Column(name = "password", nullable = false)
private String password;
@Column(name = "password", nullable = false)
private String password;
/**
* 管理者権限
*/
@Column(name = "admin_auth", nullable = false)
private Integer adminAuth;
@Column(name = "admin_auth", nullable = false)
private Integer adminAuth;
@ManyToOne
@JoinColumn(name = "id_department", referencedColumnName = "id_department", insertable = false, updatable = false)
@Fetch(FetchMode.JOIN)
private DepartmentEntity department;
@ManyToOne
@JoinColumn(name = "id_department", referencedColumnName = "id_department", insertable = false, updatable = false)
@Fetch(FetchMode.JOIN)
private DepartmentEntity department;
/**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。
*
* @param employeeDepartmentEntity  EmployeeDepartmentEntity のインスタンス
* @return EmployeeInfo のインスタンス
*/
public static EmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) {
public static EmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) {
// コンストラクタを使って書くとSetterを使用するより簡略化出来ます。
// 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、
// どうしてこの書き方が出来るのかを理解できる様になりましょう。
return new EmployeeInfo(
new Employee(
employeeDepartmentEntity.getIdEmployee(),
employeeDepartmentEntity.getNmEmployee(),
employeeDepartmentEntity.getKnEmployee(),
employeeDepartmentEntity.getMailAddress(),
employeeDepartmentEntity.getPassword(),
employeeDepartmentEntity.getAdminAuth(),
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment()
),
new Department(
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment(),
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getNmDepartment()
)
);
return new EmployeeInfo(
new Employee(
employeeDepartmentEntity.getIdEmployee(),
employeeDepartmentEntity.getNmEmployee(),
employeeDepartmentEntity.getKnEmployee(),
employeeDepartmentEntity.getMailAddress(),
employeeDepartmentEntity.getPassword(),
employeeDepartmentEntity.getAdminAuth(),
employeeDepartmentEntity.getDepartment() == null ? null
: employeeDepartmentEntity.getDepartment().getIdDepartment()),
new Department(
employeeDepartmentEntity.getDepartment() == null ? null
: employeeDepartmentEntity.getDepartment().getIdDepartment(),
employeeDepartmentEntity.getDepartment() == null ? null
: employeeDepartmentEntity.getDepartment().getNmDepartment()));
}
}
/**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。
* (リスト版)
*
* @param employeeDepartmentEntityList EmployeeDepartmentEntity インスタンスのリスト
* @return EmployeeInfo インスタンスのリスト
*/
public static List<EmployeeInfo> createEmployeeInfoList(List<EmployeeDepartmentEntity> employeeDepartmentEntityList) {
public static List<EmployeeInfo> createEmployeeInfoList(
List<EmployeeDepartmentEntity> employeeDepartmentEntityList) {
// StreamAPI を使うとこうなります。
return employeeDepartmentEntityList.stream().map(EmployeeDepartmentEntity::createEmployeeInfo).toList();
}
return employeeDepartmentEntityList.stream().map(EmployeeDepartmentEntity::createEmployeeInfo).toList();
}
}

View File

@@ -1,27 +1,22 @@
/*
* Employee.java
* 作成 IT-College 2016
*------------------------------------------------------------
* Copyright(c) Rhizome Inc. All Rights Reserved.
*/
package com.example.rhizome.app.infra.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.List;
/**
* EmployeeテーブルのEntity
*
* @author IT-College
*/
@Entity
@Table(name = "employee")
@Data
@@ -29,146 +24,77 @@ import java.util.List;
@AllArgsConstructor
public class EmployeeEntity {
/**
* 社員ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_employee", nullable = false)
private Integer idEmployee;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_employee", nullable = false)
private Integer idEmployee;
/**
* 社員名
*/
@Column(name = "nm_employee", nullable = false)
private String nmEmployee;
@Column(name = "nm_employee", nullable = false)
private String nmEmployee;
/**
* 社員名カナ
*/
@Column(name = "kn_employee", nullable = false)
private String knEmployee;
@Column(name = "kn_employee", nullable = false)
private String knEmployee;
/**
* メールアドレス
*/
@Column(name = "mail_address", nullable = false)
private String mailAddress;
@Column(name = "mail_address", nullable = false)
private String mailAddress;
/**
* パスワード
*/
@Column(name = "password", nullable = false)
private String password;
@Column(name = "password", nullable = false)
private String password;
/**
* 管理者権限
*/
@Column(name = "admin_auth", nullable = false)
private Integer adminAuth;
@Column(name = "admin_auth", nullable = false)
private Integer adminAuth;
/**
* 部署ID
*/
@Column(name = "id_department", nullable = false)
private Integer idDepartment;
@Column(name = "id_department", nullable = false)
private Integer idDepartment;
public static EmployeeEntity convertFrom(Employee employee) {
return new EmployeeEntity(
employee.getIdEmployee(),
employee.getNmEmployee(),
employee.getKnEmployee(),
employee.getMailAddress(),
employee.getPassword(),
employee.getAdminAuth(),
employee.getIdDepartment());
}
/**
* Employee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。
*
* @param employee Employee Table の中身
* @return EmployeeEntity のインスタンス(1レコード分)
*/
public static EmployeeEntity convertFrom(Employee employee) {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return new EmployeeEntity(
employee.getIdEmployee(),
employee.getNmEmployee(),
employee.getKnEmployee(),
employee.getMailAddress(),
employee.getPassword(),
employee.getAdminAuth(),
employee.getIdDepartment()
);
}
public static EmployeeEntity convertFrom(SearchConditionEmployee searchConditionEmployee) {
EmployeeEntity employeeEntity = new EmployeeEntity();
/**
* SearchConditionEmployee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。
* (コンストラクタを使用せず、Setterを利用したパターン)
*
* @param searchConditionEmployee 検索条件
* @return EmployeeEntity のインスタンス(1レコード分)
*/
public static EmployeeEntity convertFrom(SearchConditionEmployee searchConditionEmployee) {
EmployeeEntity employeeEntity = new EmployeeEntity();
employeeEntity.setIdEmployee(searchConditionEmployee.getIdEmployee());
employeeEntity.setNmEmployee(searchConditionEmployee.getNmEmployee());
employeeEntity.setKnEmployee(searchConditionEmployee.getKnEmployee());
employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress());
employeeEntity.setIdDepartment(searchConditionEmployee.getIdDepartment());
employeeEntity.setIdEmployee(searchConditionEmployee.getIdEmployee());
employeeEntity.setNmEmployee(searchConditionEmployee.getNmEmployee());
employeeEntity.setKnEmployee(searchConditionEmployee.getKnEmployee());
employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress());
employeeEntity.setIdDepartment(searchConditionEmployee.getIdDepartment());
return employeeEntity;
}
return employeeEntity;
public static Employee createEmployee(EmployeeEntity employeeEntity) {
return new Employee(
employeeEntity.getIdEmployee(),
employeeEntity.getNmEmployee(),
employeeEntity.getKnEmployee(),
employeeEntity.getMailAddress(),
employeeEntity.getPassword(),
employeeEntity.getAdminAuth(),
employeeEntity.getIdDepartment());
}
}
public static List<Employee> createEmployeeList(List<EmployeeEntity> employeeEntityList) {
return employeeEntityList.stream().map(EmployeeEntity::createEmployee).toList();
}
/**
* EmployeeEntity(DataAccess層依存)から Employee (BusinessLogic層依存型)に変換します。
*
* @param employeeEntity Employee Table のインスタンス
* @return employee インスタンス
*/
public static Employee createEmployee(EmployeeEntity employeeEntity) {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return new Employee(
employeeEntity.getIdEmployee(),
employeeEntity.getNmEmployee(),
employeeEntity.getKnEmployee(),
employeeEntity.getMailAddress(),
employeeEntity.getPassword(),
employeeEntity.getAdminAuth(),
employeeEntity.getIdDepartment()
);
}
/**
* EmployeeEntity(DataAccess層依存) から Employee (BusinessLogic層依存型)に変換します。(リスト版)
*
* @param employeeEntityList EmployeeEntity インスタンスのリスト
* @return Employee インスタンスのリスト
*/
public static List<Employee> createEmployeeList(List<EmployeeEntity> employeeEntityList) {
/* 従来の書き方
List<Employee> employeeList = new ArrayList<>();
for(EmployeeEntity employeeEntity:employeeEntityList){
Employee employee = EmployeeEntity.createEmployee(employeeEntity);
employeeList.add(employee);
}
return employeeList;
*/
// Stream APIを使用すると1行で書けます。
return employeeEntityList.stream().map(EmployeeEntity::createEmployee).toList();
}
/**
* EmployeeEntity(DataAccess層依存) から LoginUser (BusinessLogic層依存型)情報を作成します。
*
* @return loginUser (ログイン者の情報) インスタンス
*/
public LoginUser createLoginUser() {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return new LoginUser(
getIdEmployee(),
getNmEmployee(),
getKnEmployee(),
getMailAddress(),
getPassword(),
getAdminAuth(),
getIdDepartment()
);
}
public LoginUser createLoginUser() {
return new LoginUser(
getIdEmployee(),
getNmEmployee(),
getKnEmployee(),
getMailAddress(),
getPassword(),
getAdminAuth(),
getIdDepartment());
}
}