📄 product.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.Collection;
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.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
/**
* @author Borys Burnayev
*/
@Entity
@Table(name = "product")
@SequenceGenerator(name = "ProductSeq", sequenceName = "sq_product")
public class Product {
private Integer productId;
private String code;
private String name;
private String description;
private String imagePath;
private Collection<Category> categories;
private Collection<Item> items;
public Product(String code, String name, String description, String imagePath) {
this();
this.code = code;
this.name = name;
this.description = description;
this.imagePath = imagePath;
}
public Product() {
categories = new ArrayList<Category>(1);
items = new ArrayList<Item>(1);
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ProductSeq")
@Column(name = "product_sysid")
public Integer getProductId() {
return this.productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
@Column(name = "product_abbr")
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code = code;
}
@Column(name = "product_nm")
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "product_desc")
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@Column(name = "image_path")
public String getImagePath() {
return this.imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
@ManyToMany(mappedBy = "products", targetEntity = Category.class)
public Collection getCategories() {
return this.categories;
}
public void setCategories(Collection<Category> categories) {
this.categories = categories;
}
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "product_sysid", referencedColumnName = "product_sysid")
public Collection<Item> getItems() {
return this.items;
}
public void setItems(Collection<Item> items) {
this.items = items;
}
public String toString() {
String id = productId != null ? productId.toString() : "<no ID>";
return "Product " + id + ":\nCode: " + code + "\nDescription: " + description + "\nName: " + name
+ "\nImage Path: " + imagePath + "\n";
}
public boolean equals(Object object) {
if (!(object instanceof Product))
return false;
Product product = (Product) object;
return code.equals(product.getCode());
}
public int hashCode() {
return code.hashCode();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -