自動生成機能のイメージをつかむためのサンプルです。
ドメインモデルらしい振る舞い (メソッド) やサービス・メソッドはありません。
package mycom.domain;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import mycom.domain.ddb.DdBaseEntity;
/**
* 製品
*/
@Entity
public class Product extends DdBaseEntity {
/** 製品名 */
private String name;
/** 在庫リスト */
@OneToMany(mappedBy="product")
private List<Stock> stockList;
/** コンストラクタ */
public Product() {
super();
this.name = "";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Stock> getStockList() {
return stockList;
}
public void setStockList(List<Stock> stockList) {
this.stockList = stockList;
}
@Override
public String getDDBEntityTitle() {
return "タイトル: " + this.getName();
}
}
package mycom.domain;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import mycom.domain.ddb.DdBaseEntity;
/**
* 倉庫
*/
@Entity
public class Warehouse extends DdBaseEntity {
/** 倉庫名 */
private String name;
/** 在庫リスト */
@OneToMany(mappedBy="warehouse", cascade=CascadeType.ALL, orphanRemoval=true)
private List<Stock> stockList;
/** コンストラクタ */
public Warehouse() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Stock> getStockList() {
return stockList;
}
public void setStockList(List<Stock> stockList) {
this.stockList = stockList;
}
@Override
public String getDDBEntityTitle() {
return "タイトル: " + this.getName();
}
}
package mycom.domain;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import mycom.domain.ddb.DdBaseEntity;
/**
* 在庫
*/
@Entity
public class Stock extends DdBaseEntity {
/** 倉庫 */
@ManyToOne
private Warehouse warehouse;
/** 商品 */
@ManyToOne
private Product product;
/** 数量 */
private Integer amount;
public Stock() {
super();
}
public Warehouse getWarehouse() {
return warehouse;
}
public void setWarehouse(Warehouse warehouse) {
this.warehouse = warehouse;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
@Override
public String getDDBEntityTitle() {
String title = this.getProduct() != null ? this.getProduct().getName() : "";
return "タイトル: " + title;
}
}
package mycom.service;
import mycom.domain.Product;
import mycom.domain.Warehouse;
import mycom.service.ddb.DdBaseService;
/**
* 在庫サービス
*/
public class StockService extends DdBaseService {
/**
* 倉庫間移動
* @param from
* @param to
* @param product
* @param amount
* @return
*/
public String moveProduct(
Warehouse from,
Warehouse to,
Product product,
Integer amount
){
//実際の移動処理は未実装です。
String result = "完了。"
+ from.getName() + " → "
+ to.getName()
+ " 商品: " + product.getName() + " 数量: " + amount;
return result;
}
}