Java tutorial
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package com.gst.portfolio.group.domain; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import com.gst.infrastructure.core.domain.AbstractAuditableCustom; import com.gst.organisation.staff.domain.Staff; import com.gst.useradministration.domain.AppUser; import org.joda.time.LocalDate; @Entity @Table(name = "m_staff_assignment_history") public class StaffAssignmentHistory extends AbstractAuditableCustom<AppUser, Long> { @ManyToOne @JoinColumn(name = "centre_id", nullable = true) private Group center; @ManyToOne @JoinColumn(name = "staff_id", nullable = true) private Staff staff; @Temporal(TemporalType.DATE) @Column(name = "start_date") private Date startDate; @Temporal(TemporalType.DATE) @Column(name = "end_date") private Date endDate; public static StaffAssignmentHistory createNew(final Group center, final Staff staff, final LocalDate startDate) { return new StaffAssignmentHistory(center, staff, startDate.toDate(), null); } protected StaffAssignmentHistory() { // } private StaffAssignmentHistory(final Group center, final Staff staff, final Date startDate, final Date endDate) { this.center = center; this.staff = staff; this.startDate = startDate; this.endDate = endDate; } public void updateStaff(final Staff staff) { this.staff = staff; } public void updateStartDate(final LocalDate startDate) { this.startDate = startDate.toDate(); } public void updateEndDate(final LocalDate endDate) { this.endDate = endDate.toDate(); } public boolean matchesStartDateOf(final LocalDate matchingDate) { return getStartDate().isEqual(matchingDate); } public LocalDate getStartDate() { return new LocalDate(this.startDate); } public boolean isCurrentRecord() { return this.endDate == null; } }