Java tutorial
/* * Copyright 2015-2016 USEF Foundation * * Licensed 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 energy.usef.agr.model; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.ForeignKey; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Temporal; import javax.persistence.TemporalType; import org.joda.time.LocalDate; /** * Abstract class for {@link DeviceRequest}, with the core information */ @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class DeviceRequest { @Id @Column(name = "ID", nullable = false, length = 36) private String id; @Column(name = "PERIOD", nullable = false) @Temporal(TemporalType.DATE) private Date period; @ManyToOne @JoinColumn(name = "DEVICE_MESSAGE_ID", foreignKey = @ForeignKey(name = "DR_DEVICE_MESSAGE_FK"), nullable = false) private DeviceMessage deviceMessage; public DeviceRequest(LocalDate period) { setPeriod(period); } public String getId() { return id; } public void setId(String id) { this.id = id; } public LocalDate getPeriod() { if (period == null) { return null; } return new LocalDate(period); } public void setPeriod(LocalDate period) { if (period == null) { this.period = null; } else { this.period = period.toDateMidnight().toDate(); } } public DeviceMessage getDeviceMessage() { return deviceMessage; } public void setDeviceMessage(DeviceMessage deviceMessage) { this.deviceMessage = deviceMessage; } }