140 likes | 479 Views
CSE446 Software Quality Management. Orhan Ba şar Evren. Spring 2014. Yazılım ve Uyguluma Geliştirme Yöneticisi. Today’s Overview. EJB : Enterprise Java Beans What is EJB ? EJB Container Bean Types Remote and Local Examples JPA and EJB. EJB – Enterprise Java Beans.
E N D
CSE446 Software Quality Management Orhan Başar Evren Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi
Today’s Overview • EJB : Enterprise Java Beans • What is EJB ? • EJB Container • Bean Types • Remote and Local • Examples • JPA and EJB CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Enterprise Java Beans • EJB technology is a server-side component architecture that enables rapid and simplified development of distributed, transactional, secure, and portable applications. • Enterprise beans run in the EJB container • Server-side component that encapsulates the business logic of an application. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – EJB Container • Container is holding objects on server • Container creates and manages enterprise bean instances at runtime • Container isolates beans from clients • Transaction Management • Persistence Management • Security Management • Containers provide JNDI service CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – EJB Container CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Bean Types • Session Bean:High level business logic and processes • Message Driven Bean: Integrate with external services via asynchronous messages using JMS (Java Messaging Service) CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Session Beans • Invoked by a client in order perform a business operation. The bean instance is available for the duration of a unit work. • @Stateless: used for operations that can occur in a single method call • @Stateful: State is maintained across multiple method calls. • @Singleton: Bean is instantiated once per application CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Session Bean Example @Stateless public class CalculatorBeanimplements Calculator { public intadd (int n1, intn2) { return n1 + n2; } public intsubtract(intn1, intn2) { return n1 – n2; } } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Session Bean Example @MessageDriven public classCalculatorBean implements MessageListener { public void onMessage(Message message) { System.out.println("A message arrived!"); } } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Remote and Local Interfaces • @Remote: Used to allow remote access. Clients can call those methods from another java EE applications, or from other java SE desktop applications. Beans are remotely accessed using JNDI . (Java Naming and Directory Interface) • @Local : Allow only local access within the container. Beans locally accessed using @EJB annotation CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Local Access Example @ManagedBean public class JSFBean { @EJB Calculator calc; public voiddoMath() { intresult = calc.add(10,5); } } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Remote Access Example public class DesktopClient { public static void main(String[] args) { InitialContextic = new InitialContext(); Calculator calc = (Calculator) ic.lookup("java:comp/env/app/Test"); int result = calc.add(10, 5); } } JNDI , URL, and other information can be stored on a properties file. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB – Security and Transaction @Stateless @DeclareRoles({“user" “admin"}) public class RegistrationService { @RolesAllowed({“user"}) public void register(String event) { … } @RolesAllowed({“admin”}) public voidcreate(String event) { … } @Transactional public voidcreateAndRegister(String event) { create(event); register(event); } } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
EJB –Other Examples • Demonstration of @EJB usage with in Web Application to manage transactions. • Demonstration of Java Enterprise Application with simple math functionalities as business logic. (Use of ear files) • Accessing business logic locally from a JSF managed bean • Accessing business logic remotely from a Desktop app. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş