ひがやすを技術ブログ

電通国際情報サービスのプログラマ

サンプルアプリ

churaのイメージをつかんでもらうために、単純なサンプルを元に説明します。まだ、実装されていないところもありますが、イメージということで。
このサンプルは、従業員管理のアプリケーションです。S2JSF-exampleに出てくるやつの簡易版です。テーブルは次の2つです。


CREATE TABLE department (
id NUMERIC(9) NOT NULL PRIMARY KEY,
name VARCHAR(20)
);
CREATE TABLE employee (
id NUMERIC(9) NOT NULL PRIMARY KEY,
name VARCHAR(20),
deparment_id NUMERIC(9),
CONSTRAINT fk_department_id FOREIGN KEY (department_id)
REFERENCES department(id)
);
このスキーマ情報を元に次のEntity、Dao、EntityLogicの雛型を自動生成します。

@Entity
public class Department {
@Id(generate=GeneratorType.AUTO)
private int id;
private String name;
...
}
@Entity
public class Employee {
@Id(generate=GeneratorType.AUTO)
private int id;
private String name;
@ManyToOne
private Department department;
...
}

public interface DepartmentDao {
List findAll();
Department find(int id);
void persist(Department department);
void remove(Department department);
boolean contains(Department department);
Employee merge(Department department);
void refresh(Department department);
void readLock(Department department);
void writeLock(Department department);
}
public interface EmployeeDao {
List findAll();
Employee find(int id);
void persist(Employee employee);
void remove(Employee employee);
boolean contains(Employee employee);
Employee merge(Employee employee);
void refresh(Employee employee);
void readLock(Employee employee);
void writeLock(Employee employee);
}
Daoの実装は、AOPで自動生成されるので、必要ありません。

public interface DepartmentLogic {
List findAll();
Department find(int id);
void persist(Department department);
void remove(Department department);
}
public interface EmployeeLogic {
List findAll();
Employee find(int id);
void persist(Employee employee);
void remove(Employee employee);
}
EntityLogicについては、実装クラスの雛型も作成されます。

public class DepartmentLogicImpl implements DepartmentLogic {
private DepartmentDao dao;
...
List findAll() {
return dao.findAll();
}
...
}
public class EmployeeLogicImpl implements EmployeeLogic {
private EmployeeDao dao;
...
List findAll() {
return dao.findAll();
}
...
}