デモアプリケーションを作成しました.JSF & EJB 3.0(ステートレスセッションBeanとJPA)を使用していました。永続性プロバイダはHibernate 4で、データベースはApache Derbyです。JSF、EJB 3.0を使用するアプリケーションの設計パターンを提案
次のように一連の流れすなわち私のクラスの流れがあり、
ManagedBeanが
、 JSFは、Bean StudentMgBean.javaを管理し、コードに従ってください、これで我々はJPAコールを持って、ステートレスセッションBeanを呼び出します
@ManagedBean(name="stMgBean")
@ViewScoped
public class StudentMgBean implements Serializable{
private static final long serialVersionUID = 109117543434170143L;
...........
@EJB
private StudentService studentService;
.........
@PostConstruct
public void init(){
..........
........
this.totalStudentInDB = studentService.getMaxStudent();
}
}
マイEJBインターフェースStudentService.java、
@Local
public interface StudentService {
List<StudentVO> fetchStudentListOrderByStudentId(boolean flag);
List<StudentVO> fetchStudentListOrderByStudentName(boolean flag);
void saveStudentEntity(StudentEntity studentEntity,Integer deptId) throws Exception;
List<DeptEntity> fetchAllDept();
List<StudentVO> fetchStudentByDept(Integer deptId);
void saveAllStudents(List<StudentVO> students) throws Exception;
void deleteAllStudents(List<StudentVO> students) throws Exception;
List<StudentVO> fetchStudentListPerPage(Integer minRow,Integer maxRow) throws Exception;
Integer getMaxStudent() throws Exception;
}
マイEJBステートレスSession Bean StudentServiceBean.java、StudentServiceBeanで
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class StudentServiceBean implements StudentService{
@PersistenceContext(unitName="forPractise")
private EntityManager entityMgr;
@Resource
private SessionContext sessionContext;
@EJB
private DeptService deptService;
@Override
public List<StudentVO> fetchStudentListOrderByStudentId(boolean flag){
.........
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveStudentEntity(StudentEntity studentEntity,Integer deptId) throws Exception{
........
}
}
は、私はEntityManagerを注入しているので、私は直接このセッションBeanで記述された方法でJPAの操作を行います。
私は別のDAOレイヤー として、このフローで任意のデザインパターンを使用できますか?私はEJB 3.0を使用しています。私はServiceLocatorパターンを使用する必要はありませんが、他のパターン私は1つのより多くの事
、JPAの呼び出しで商務ロジックを区切るために使用し、JSFでは は、私はこの 値= {stMgBean.studentListのようなELでのJSP componenetsにマッピングされているプロパティとそのゲッターセッターメソッドを持つBeanの管理しました}
でも同じ管理対象Beanには、JSFのアクションコマンド呼び出しで呼び出されるメソッドもあります。 これらのメソッドを個別のManaged Beanに記述する必要がありますか?
返事を待っているJSF 2.0、EJB 3.0とJPA
を持っているプロジェクトのために使用することができるデザインパターンを提案してください
複数の異なる永続性プロバイダがない場合は、DAOを使用しないでください。これはアーキテクチャを過度に複雑にします。 –
OKですが、私のクラスフローは大きなプロジェクトには十分ですか、あるいは、マネージドBeanをアクションコマンドメソッドのために2つに分割する必要がありますか?getterとsetterのマップされたプロパティの別のクラス、Bussinessレイヤのクラス階層私は、EJBを使用して、返信を待っています –
あなたは2つのタイプのマネージドビーンズ - コントローラー(uiロジックとコールビジネスレイヤーを実行する)とエンティティ(jpa @Entities)を持ち、ロジックなしでデータを転送します。ビジネスレイヤーに階層を設ける必要はありません。再利用するものがあれば、別のコンポーネントで移動し、複数の場所で使用できます。 –