[STYLE] entityの無駄な改行やスペースなどの削除
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
* DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。
|
||||
*
|
||||
* @param departmentEntityList department Table のリスト
|
||||
* @return List<Department> リスト
|
||||
*/
|
||||
public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) {
|
||||
|
||||
// Stream API を利用するとこうなります。
|
||||
return departmentEntityList
|
||||
.stream()
|
||||
.map(departmentEntity -> new Department(
|
||||
departmentEntity.getIdDepartment(),
|
||||
departmentEntity.getNmDepartment()
|
||||
)).toList();
|
||||
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()
|
||||
);
|
||||
department.getNmDepartment());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +1,53 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* 社員名
|
||||
*/
|
||||
@Column(name = "nm_employee", nullable = false)
|
||||
private String nmEmployee;
|
||||
|
||||
/**
|
||||
* 社員名カナ
|
||||
*/
|
||||
@Column(name = "kn_employee", nullable = false)
|
||||
private String knEmployee;
|
||||
|
||||
/**
|
||||
* メールアドレス
|
||||
*/
|
||||
@Column(name = "mail_address", nullable = false)
|
||||
private String mailAddress;
|
||||
|
||||
/**
|
||||
* パスワード
|
||||
*/
|
||||
@Column(name = "password", nullable = false)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 管理者権限
|
||||
*/
|
||||
@Column(name = "admin_auth", nullable = false)
|
||||
private Integer adminAuth;
|
||||
|
||||
@@ -71,17 +56,8 @@ public class EmployeeDepartmentEntity {
|
||||
@Fetch(FetchMode.JOIN)
|
||||
private DepartmentEntity department;
|
||||
|
||||
/**
|
||||
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。
|
||||
*
|
||||
* @param employeeDepartmentEntity EmployeeDepartmentEntity のインスタンス
|
||||
* @return EmployeeInfo のインスタンス
|
||||
*/
|
||||
public static EmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) {
|
||||
|
||||
// コンストラクタを使って書くとSetterを使用するより簡略化出来ます。
|
||||
// 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、
|
||||
// どうしてこの書き方が出来るのかを理解できる様になりましょう。
|
||||
return new EmployeeInfo(
|
||||
new Employee(
|
||||
employeeDepartmentEntity.getIdEmployee(),
|
||||
@@ -90,29 +66,21 @@ public class EmployeeDepartmentEntity {
|
||||
employeeDepartmentEntity.getMailAddress(),
|
||||
employeeDepartmentEntity.getPassword(),
|
||||
employeeDepartmentEntity.getAdminAuth(),
|
||||
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment()
|
||||
),
|
||||
employeeDepartmentEntity.getDepartment() == null ? null
|
||||
: employeeDepartmentEntity.getDepartment().getIdDepartment()),
|
||||
new Department(
|
||||
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment(),
|
||||
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getNmDepartment()
|
||||
)
|
||||
);
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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,59 +24,30 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class EmployeeEntity {
|
||||
|
||||
/**
|
||||
* 社員ID
|
||||
*/
|
||||
@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 = "kn_employee", nullable = false)
|
||||
private String knEmployee;
|
||||
|
||||
/**
|
||||
* メールアドレス
|
||||
*/
|
||||
@Column(name = "mail_address", nullable = false)
|
||||
private String mailAddress;
|
||||
|
||||
/**
|
||||
* パスワード
|
||||
*/
|
||||
@Column(name = "password", nullable = false)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 管理者権限
|
||||
*/
|
||||
@Column(name = "admin_auth", nullable = false)
|
||||
private Integer adminAuth;
|
||||
|
||||
/**
|
||||
* 部署ID
|
||||
*/
|
||||
@Column(name = "id_department", nullable = false)
|
||||
private Integer idDepartment;
|
||||
|
||||
|
||||
/**
|
||||
* Employee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。
|
||||
*
|
||||
* @param employee Employee Table の中身
|
||||
* @return EmployeeEntity のインスタンス(1レコード分)
|
||||
*/
|
||||
public static EmployeeEntity convertFrom(Employee employee) {
|
||||
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
|
||||
return new EmployeeEntity(
|
||||
employee.getIdEmployee(),
|
||||
employee.getNmEmployee(),
|
||||
@@ -89,17 +55,9 @@ public class EmployeeEntity {
|
||||
employee.getMailAddress(),
|
||||
employee.getPassword(),
|
||||
employee.getAdminAuth(),
|
||||
employee.getIdDepartment()
|
||||
);
|
||||
employee.getIdDepartment());
|
||||
}
|
||||
|
||||
/**
|
||||
* SearchConditionEmployee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。
|
||||
* (コンストラクタを使用せず、Setterを利用したパターン)
|
||||
*
|
||||
* @param searchConditionEmployee 検索条件
|
||||
* @return EmployeeEntity のインスタンス(1レコード分)
|
||||
*/
|
||||
public static EmployeeEntity convertFrom(SearchConditionEmployee searchConditionEmployee) {
|
||||
EmployeeEntity employeeEntity = new EmployeeEntity();
|
||||
|
||||
@@ -109,19 +67,11 @@ public class EmployeeEntity {
|
||||
employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress());
|
||||
employeeEntity.setIdDepartment(searchConditionEmployee.getIdDepartment());
|
||||
|
||||
|
||||
return employeeEntity;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* EmployeeEntity(DataAccess層依存)から Employee (BusinessLogic層依存型)に変換します。
|
||||
*
|
||||
* @param employeeEntity Employee Table のインスタンス
|
||||
* @return employee インスタンス
|
||||
*/
|
||||
public static Employee createEmployee(EmployeeEntity employeeEntity) {
|
||||
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
|
||||
return new Employee(
|
||||
employeeEntity.getIdEmployee(),
|
||||
employeeEntity.getNmEmployee(),
|
||||
@@ -129,37 +79,14 @@ public class EmployeeEntity {
|
||||
employeeEntity.getMailAddress(),
|
||||
employeeEntity.getPassword(),
|
||||
employeeEntity.getAdminAuth(),
|
||||
employeeEntity.getIdDepartment()
|
||||
);
|
||||
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(),
|
||||
@@ -167,8 +94,7 @@ public class EmployeeEntity {
|
||||
getMailAddress(),
|
||||
getPassword(),
|
||||
getAdminAuth(),
|
||||
getIdDepartment()
|
||||
);
|
||||
getIdDepartment());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user