📄 account.java
字号:
/*
* Copyright 2006 Borys Burnayev
*
* 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 com.rdacorp.petstore.domain;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;
/**
* @author Borys Burnayev
*/
@Entity
@Table(name = "account")
@SequenceGenerator(name = "AccountSeq", sequenceName = "SQ_ACCOUNT")
public class Account {
private Integer accountId;
private Person person;
private Address address;
private List<Payment> payments;
private int version;
@Column(name = "row_version")
@Version
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public Account(Person person, Address address) {
this();
this.person = person;
this.address = address;
person.setAccount(this);
}
public Account() {
payments = new ArrayList<Payment>(1);
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AccountSeq")
@Column(name = "account_sysid")
public Integer getAccountId() {
return this.accountId;
}
public void setAccountId(Integer accountId) {
this.accountId = accountId;
}
@OneToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST })
@JoinColumn(name = "PERSON_SYSID")
public Person getPerson() {
return this.person;
}
public void setPerson(Person person) {
this.person = person;
}
@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST })
@JoinColumn(name = "ADDRESS_SYSID")
public Address getAddress() {
return this.address;
}
public void setAddress(Address location) {
this.address = location;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "account")
public List<Payment> getPayments() {
return this.payments;
}
public void setPayments(List<Payment> payments) {
this.payments = payments;
}
public String toString() {
String id = accountId != null ? accountId.toString() : "<no ID>";
return "Account " + id + ":\n" + person + address;
}
public boolean equals(Object object) {
if (!(object instanceof Account))
return false;
Account account = (Account) object;
return person.equals(account.getPerson()) && address.equals(account.getAddress());
}
public int hashCode() {
return person.hashCode() + address.hashCode();
}
public boolean isAddressOnFile(Address address) {
Address addressOnFile = getAddress();
return addressOnFile.getAddressLine1().equals(address.getAddressLine1())
&& addressOnFile.getAddressLine2().equals(address.getAddressLine2())
&& addressOnFile.getCity().equals(address.getCity())
&& addressOnFile.getState().getCode().equals(address.getState().getCode())
&& addressOnFile.getZip().equals(address.getZip());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -