Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
onacit committed Jun 18, 2024
1 parent 09c82a7 commit 81d3162
Show file tree
Hide file tree
Showing 23 changed files with 430 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .idea/codeStyles
Submodule codeStyles updated 1 files
+2 −5 Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertFalse;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;
Expand Down Expand Up @@ -110,8 +111,15 @@ public class DeptEmp
public static final String TABLE_NAME = "dept_emp";

// ---------------------------------------------------------------------------------------------------------- emp_no

/**
* The name of the table column to which the {@link DeptEmp_#empNo empNo} attribute maps. The value is {@value}.
*/
public static final String COLUMN_NAME_EMP_NO = Employee.COLUMN_NAME_EMP_NO;

/**
* The name of the entity attribute from which the {@value #COLUMN_NAME_EMP_NO} column maps. The value is {@value}.
*/
public static final String ATTRIBUTE_NAME_EMP_NO = "empNo";

public static final String ATTRIBUTE_NAME_EMPLOYEE = "employee";
Expand Down Expand Up @@ -190,7 +198,7 @@ private void onPrePersist() {
* @return {@code true} if current value of the {@link DeptEmp_#fromDate fromDate} attribute <em>is after</em>
* current value of the {@link DeptEmp_#toDate toDate} attribute; {@code false} otherwise.
*/
// @jakarta.validation.constraints.AssertFalse(message = "fromDate shouldn't be after the toDate")
@AssertFalse(message = "fromDate shouldn't be after the toDate")
private boolean isFromDateAfterToDate() {
if (fromDate == null || toDate == null) {
return false;
Expand All @@ -205,7 +213,7 @@ private boolean isFromDateAfterToDate() {
* @return {@code true} if current value of the {@link DeptEmp_#toDate toDate} attribute <em>is after</em> the
* {@link #ATTRIBUTE_VALUE_TO_DATE_UNSPECIFIED}; {@code false} otherwise.
*/
// @jakarta.validation.constraints.AssertFalse
@AssertFalse(message = "toDate shouldn't be after the 9999-01-01")
private boolean isToDateAfterTheUnspecified() {
if (toDate == null) {
return false;
Expand All @@ -215,6 +223,26 @@ private boolean isToDateAfterTheUnspecified() {

// ------------------------------------------------------------------------------------------------- emp_no/employee

/**
* Returns current value of {@link DeptEmp_#empNo empNo} attribute.
*
* @return current value of the {@link DeptEmp_#empNo empNo} attribute.
*/
// TODO: narrow the scope
public Integer getEmpNo() {
return empNo;
}

/**
* Replaces current value of {@link DeptEmp_#empNo empNo} attribute with specified value.
*
* @param empNo new value for the {@link DeptEmp_#empNo empNo} attribute.
*/
// TODO: narrow the scope
public void setEmpNo(final Integer empNo) {
this.empNo = empNo;
}

/**
* Returns current value of {@link DeptEmp_#employee employee} attribute.
*
Expand All @@ -240,11 +268,39 @@ public void setEmployee(final Employee employee) {
);
}

/**
* Replaces current value of {@link DeptEmp_#employee employee} attribute with specified value, and returns this
* entity.
*
* @param employee new value for the {@link DeptEmp_#employee employee} attribute.
* @return this entity.
* @implSpec Default implementation invokes {@link #setEmployee(Employee)} method with {@code employee}, and returns
* {@code this}.
*/
public DeptEmp employee(final Employee employee) {
setEmployee(employee);
return this;
}

// ---------------------------------------------------------------------------------------------- dept_no/department
// TODO: put javadoc
// TODO: narrow the scope
public String getDeptNo() {
return deptNo;
}

// TODO: put javadoc
// TODO: narrow the scope
public void setDeptNo(final String deptNo) {
this.deptNo = deptNo;
}

// TODO: put javadoc
public Department getDepartment() {
return department;
}

// TODO: put javadoc
public void setDepartment(final Department department) {
this.department = department;
setDeptNo(
Expand All @@ -254,16 +310,65 @@ public void setDepartment(final Department department) {
);
}

// TODO: put javadoc
public DeptEmp department(final Department department) {
setDepartment(department);
return this;
}

// -------------------------------------------------------------------------------------------------------- fromDate

/**
* Returns current value of {@link DeptEmp_#fromDate fromDate} attribute.
*
* @return current value of {@link DeptEmp_#fromDate fromDate} attribute.
*/
public LocalDate getFromDate() {
return fromDate;
}

/**
* Replaces current value of {@link DeptEmp_#fromDate fromDate} attribute with specified value.
*
* @param fromDate new value for the {@link DeptEmp_#fromDate fromDate} attribute.
*/
public void setFromDate(final LocalDate fromDate) {
this.fromDate = fromDate;
}

/**
* Replaces current value of {@link DeptEmp_#fromDate fromDate} attribute with specified value, and returns this
* object.
*
* @param fromDate new value for the {@link DeptEmp_#fromDate fromDate} attribute.
* @return this object.
*/
public DeptEmp fromDate(final LocalDate fromDate) {
setFromDate(fromDate);
return this;
}

// ---------------------------------------------------------------------------------------------------------- toDate
// TODO: put javadoc
public LocalDate getToDate() {
return toDate;
}

// TODO: put javadoc
public void setToDate(final LocalDate toDate) {
this.toDate = toDate;
}

// TODO: put javadoc
public DeptEmp toDate(final LocalDate toDate) {
setToDate(toDate);
return this;
}

// -----------------------------------------------------------------------------------------------------------------
@NotNull
@Id
@Column(name = COLUMN_NAME_EMP_NO, nullable = false, insertable = true, updatable = false)
// @lombok.Setter(AccessLevel.PACKAGE)
// @lombok.Getter(AccessLevel.PACKAGE)
private Integer empNo;

@Valid
Expand All @@ -279,8 +384,6 @@ public void setDepartment(final Department department) {
@Id
@Column(name = COLUMN_NAME_DEPT_NO, length = COLUMN_LENGTH_DEPT_NO, nullable = false, insertable = true,
updatable = false)
// @lombok.Setter(AccessLevel.PACKAGE)
// @lombok.Getter(AccessLevel.PACKAGE)
private String deptNo;

@Valid
Expand All @@ -291,10 +394,9 @@ public void setDepartment(final Department department) {
private Department department;

// -----------------------------------------------------------------------------------------------------------------
// @jakarta.validation.constraints.PastOrPresent
@NotNull
@Basic(optional = false)
@Column(name = COLUMN_NAME_FROM_DATE, nullable = false, insertable = true, updatable = true)
@Column(name = COLUMN_NAME_FROM_DATE, nullable = false, insertable = true, updatable = false)
private LocalDate fromDate;

@NotNull
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ SELECT e.gender, AVG(s.salary)
})
public class Salary
extends _BaseEntity<SalaryId>
implements ILocalDateSpan {
implements _ILocalDateTerm {

@Serial
private static final long serialVersionUID = 604718367871825963L;
Expand Down Expand Up @@ -120,12 +120,12 @@ private boolean isFromDateNotAfterToDate() {
// -------------------------------------------------------------------------------------------------- ILocalDateSpan

@Override
public LocalDate getStart_() {
public LocalDate getTermStart() {
return getFromDate();
}

@Override
public LocalDate getEnd_() {
public LocalDate getTermEnd() {
return getToDate();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.jinahya.mysql.employees.persistence;

import java.time.chrono.ChronoLocalDate;
import java.time.temporal.TemporalAmount;

@SuppressWarnings({
"java:S114", // interface _IChrono...
"java:S119" // <TEMPORAL_ACCESSOR ...>
})
public interface _IChronoLocalDateTerm<TEMPORAL_ACCESSOR extends ChronoLocalDate, TEMPORAL_AMOUNT extends TemporalAmount>
extends _ITerm<TEMPORAL_ACCESSOR, TEMPORAL_AMOUNT> {

@Override
default boolean isTermStartNotAfterTermEnd() {
if (true) {
return _ITerm.super.isTermStartNotAfterTermEnd();
}
final TEMPORAL_ACCESSOR termStart = getTermStart();
final TEMPORAL_ACCESSOR termEnd = getTermEnd();
if (termStart == null || termEnd == null) {
return true;
}
return !termStart.isAfter(termEnd);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.jinahya.mysql.employees.persistence;

import java.time.LocalDate;
import java.time.Period;

public interface _ILocalDateTerm
extends _IChronoLocalDateTerm<LocalDate, Period> {

@Override
default Period getTermSpan() {
final var termStart = getTermStart();
final var termEnd = getTermEnd();
if (termStart == null || termEnd == null) {
return null;
}
return Period.between(termStart, termEnd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,45 @@
* @author Jin Kwon &lt;onacit_at_gmail.com&gt;
*/
@SuppressWarnings({
"java:S114", // interface _Iterm
"java:S119" // <TEMPORAL_ACCESSOR ...>
})
public interface ISpan<
public interface _ITerm<
TEMPORAL_ACCESSOR extends TemporalAccessor & Comparable<? super TEMPORAL_ACCESSOR>,
TEMPORAL_AMOUNT extends TemporalAmount> {

// ------------------------------------------------------------------------------------------------- Bean-Validation

/**
* Asserts that {@link #getStart_() start_} is not after the {@link #getEnd_() end_}.
* Asserts that {@link #getTermStart() termStart} is not after the {@link #getTermEnd() termEnd}.
*
* @return {@code true} when {@link #getStart_() start_} is not after the {@link #getEnd_() end_}; {@code false}
* otherwise; {@code true} when either {@link #getStart_() start_} or {@link #getEnd_() end_} is {@code null}.
* @return {@code true} when {@link #getTermStart() termStart} is not after the {@link #getTermEnd() termEnd};
* {@code false} otherwise; {@code true} when either {@link #getTermStart() termStart} or
* {@link #getTermEnd() termEnd} is {@code null}.
*/
@AssertTrue
default boolean isStart_IsNotAfterEnd_() {
final TEMPORAL_ACCESSOR start_ = getStart_();
final TEMPORAL_ACCESSOR end_ = getEnd_();
if (start_ == null || end_ == null) {
default boolean isTermStartNotAfterTermEnd() {
final TEMPORAL_ACCESSOR termStart = getTermStart();
final TEMPORAL_ACCESSOR termEnd = getTermEnd();
if (termStart == null || termEnd == null) {
return true;
}
return start_.compareTo(end_) <= 0;
return termStart.compareTo(termEnd) <= 0;
}

// -----------------------------------------------------------------------------------------------------------------

/**
* Returns a temporal amount between {@link #getStart_() start_} and {@link #getEnd_() end_}.
* Returns a temporal amount between {@link #getTermStart() termStart} and {@link #getTermEnd() termEnd}.
*
* @return a temporal amount between {@link #getStart_() start_} and {@link #getEnd_() end_}; {@code null} when
* either {@link #getStart_() start_} or {@link #getEnd_() end_} is {@code null}.
* @return a temporal amount between {@link #getTermStart() termStart} and {@link #getTermEnd() termEnd};
* {@code null} when either {@link #getTermStart() termStart} or {@link #getTermEnd() termEnd} is {@code null}.
*/
TEMPORAL_AMOUNT getSpan_();
TEMPORAL_AMOUNT getTermSpan();

// -----------------------------------------------------------------------------------------------------------------
TEMPORAL_ACCESSOR getStart_();
TEMPORAL_ACCESSOR getTermStart();

// -----------------------------------------------------------------------------------------------------------------
TEMPORAL_ACCESSOR getEnd_();
TEMPORAL_ACCESSOR getTermEnd();
}
Loading

0 comments on commit 81d3162

Please sign in to comment.