[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; 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 com.example.rhizome.app.domain.model.Department;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.List;
/**
* Department テーブルの Entity
*
* @author IT-College
*/
@Entity @Entity
@Table(name = "department") @Table(name = "department")
@Data @Data
@@ -27,46 +22,26 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class DepartmentEntity { public class DepartmentEntity {
/** @Id
* 部署ID @GeneratedValue(strategy = GenerationType.IDENTITY)
*/ @Column(name = "id_department", nullable = false)
@Id private Integer idDepartment;
@GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "nm_department", nullable = false)
@Column(name = "id_department", nullable = false) private String nmDepartment;
private Integer idDepartment;
/**
* 部署名
*/
@Column(name = "nm_department", nullable = false)
private String nmDepartment;
/** public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) {
* DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。
*
* @param departmentEntityList department Table のリスト
* @return List<Department> リスト
*/
public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) {
// Stream API を利用するとこうなります。 return departmentEntityList
return departmentEntityList .stream()
.stream() .map(departmentEntity -> new Department(
.map(departmentEntity -> new Department( departmentEntity.getIdDepartment(),
departmentEntity.getIdDepartment(), departmentEntity.getNmDepartment()))
departmentEntity.getNmDepartment() .toList();
)).toList(); }
}
/** public static DepartmentEntity convertFrom(Department department) {
* Department(BusinessLogic層依存型) から DepartmentEntity(DataAccess層依存)に変換します。 return new DepartmentEntity(
* department.getIdDepartment(),
* @param department department モデルの値 department.getNmDepartment());
* @return DepartmentEntity に変換したインスタンス }
*/
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; 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.Department;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo; import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; 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 @Entity
@Table(name = "employee") @Table(name = "employee")
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@NamedEntityGraph( @NamedEntityGraph(name = "employee_with_department", includeAllAttributes = true)
name = "employee_with_department",
includeAllAttributes = true
)
public class EmployeeDepartmentEntity { public class EmployeeDepartmentEntity {
/** @Id
* 社員ID @GeneratedValue(strategy = GenerationType.IDENTITY)
*/ @Column(name = "id_employee", nullable = false)
@Id private Integer idEmployee;
@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 @ManyToOne
@JoinColumn(name = "id_department", referencedColumnName = "id_department", insertable = false, updatable = false) @JoinColumn(name = "id_department", referencedColumnName = "id_department", insertable = false, updatable = false)
@Fetch(FetchMode.JOIN) @Fetch(FetchMode.JOIN)
private DepartmentEntity department; private DepartmentEntity department;
/** public static EmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) {
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。
*
* @param employeeDepartmentEntity  EmployeeDepartmentEntity のインスタンス
* @return EmployeeInfo のインスタンス
*/
public static EmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) {
// コンストラクタを使って書くとSetterを使用するより簡略化出来ます。 return new EmployeeInfo(
// 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、 new Employee(
// どうしてこの書き方が出来るのかを理解できる様になりましょう。 employeeDepartmentEntity.getIdEmployee(),
return new EmployeeInfo( employeeDepartmentEntity.getNmEmployee(),
new Employee( employeeDepartmentEntity.getKnEmployee(),
employeeDepartmentEntity.getIdEmployee(), employeeDepartmentEntity.getMailAddress(),
employeeDepartmentEntity.getNmEmployee(), employeeDepartmentEntity.getPassword(),
employeeDepartmentEntity.getKnEmployee(), employeeDepartmentEntity.getAdminAuth(),
employeeDepartmentEntity.getMailAddress(), employeeDepartmentEntity.getDepartment() == null ? null
employeeDepartmentEntity.getPassword(), : employeeDepartmentEntity.getDepartment().getIdDepartment()),
employeeDepartmentEntity.getAdminAuth(), new Department(
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment() employeeDepartmentEntity.getDepartment() == null ? null
), : employeeDepartmentEntity.getDepartment().getIdDepartment(),
new Department( employeeDepartmentEntity.getDepartment() == null ? null
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment(), : employeeDepartmentEntity.getDepartment().getNmDepartment()));
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getNmDepartment()
)
);
} }
/** public static List<EmployeeInfo> createEmployeeInfoList(
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。 List<EmployeeDepartmentEntity> employeeDepartmentEntityList) {
* (リスト版)
*
* @param employeeDepartmentEntityList EmployeeDepartmentEntity インスタンスのリスト
* @return EmployeeInfo インスタンスのリスト
*/
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; 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.Employee;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.List;
/**
* EmployeeテーブルのEntity
*
* @author IT-College
*/
@Entity @Entity
@Table(name = "employee") @Table(name = "employee")
@Data @Data
@@ -29,146 +24,77 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class EmployeeEntity { public class EmployeeEntity {
/** @Id
* 社員ID @GeneratedValue(strategy = GenerationType.IDENTITY)
*/ @Column(name = "id_employee", nullable = false)
@Id private Integer idEmployee;
@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;
/** @Column(name = "id_department", nullable = false)
* 部署ID 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());
}
/** public static EmployeeEntity convertFrom(SearchConditionEmployee searchConditionEmployee) {
* Employee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。 EmployeeEntity employeeEntity = new EmployeeEntity();
*
* @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()
);
}
/** employeeEntity.setIdEmployee(searchConditionEmployee.getIdEmployee());
* SearchConditionEmployee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。 employeeEntity.setNmEmployee(searchConditionEmployee.getNmEmployee());
* (コンストラクタを使用せず、Setterを利用したパターン) employeeEntity.setKnEmployee(searchConditionEmployee.getKnEmployee());
* employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress());
* @param searchConditionEmployee 検索条件 employeeEntity.setIdDepartment(searchConditionEmployee.getIdDepartment());
* @return EmployeeEntity のインスタンス(1レコード分)
*/
public static EmployeeEntity convertFrom(SearchConditionEmployee searchConditionEmployee) {
EmployeeEntity employeeEntity = new EmployeeEntity();
employeeEntity.setIdEmployee(searchConditionEmployee.getIdEmployee()); return employeeEntity;
employeeEntity.setNmEmployee(searchConditionEmployee.getNmEmployee());
employeeEntity.setKnEmployee(searchConditionEmployee.getKnEmployee());
employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress());
employeeEntity.setIdDepartment(searchConditionEmployee.getIdDepartment());
}
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();
}
/** public LoginUser createLoginUser() {
* EmployeeEntity(DataAccess層依存)から Employee (BusinessLogic層依存型)に変換します。 return new LoginUser(
* getIdEmployee(),
* @param employeeEntity Employee Table のインスタンス getNmEmployee(),
* @return employee インスタンス getKnEmployee(),
*/ getMailAddress(),
public static Employee createEmployee(EmployeeEntity employeeEntity) { getPassword(),
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。 getAdminAuth(),
return new Employee( getIdDepartment());
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()
);
}
} }