Lecture 5 Flashcards
What are components of business layer?
EJBs, Entities and Ordinary JavaBeans.
What are Enterprise Java Beans?
Components, Written in Java, run on server, provide services to clients (software that calls them), managed by EJB container. Must be deployed on server before used. Provide business logic. Confirm to Oracles EJB spec. My used for presentation.
Why use EJBs?
Separation of concerns, code maintainability, but they also provide networking, security, persistence based on JPA, transactions, session management, multithreading. No need for programmer to implement these himself.
Other benefits of EJBs?
Relieve other components from implementing business logic, portable and vendor independent, can be run on different host or JVM than client (unlike ordinary Java Object), more flexible, not restricted to http or stream I/O
When do you need a business tier?
If app must deal with large group of clients, needs security management, transaction management, messaging between components, or runs distributed on multiple servers.
Deployed EJBs run on the JavaEE server under management of EJB container (itself a part of the JavaEE server). When is extra functionality provided by container?
At runtime, not via linking packages as with normal Java classes.
Note: outside container EJBs are just POJOs… Why does this mean?
They can be used and tested just like normal Java objects.
Name three types of EJBs:
Session beans(stateless and stateful, and singleton), message-driven beans, entity beans (instead use JPA entities).
What is a session bean?
A server side component that interacts with a client (another component which calls beans methods), clients can be local or remote. Multiple instances created for each client. Short lived, removed when server or client ends. Does not store data in database.
The clients of session Beans are thin clients. Explain…
They only do presentation tasks, all business logic in the EJB, and all transactions security is provided by EJB container.
Explain Ststeless session beans…
Simplest kind of session beans, execute a request, don’t save any data beyond one call of a method, used for temporary piers of business logic needed by specific client.
Typical use of Stateless:
Client just needs info without any further interaction.
Stateful session beans, explain…
Each stateful interacts with one client, maintains a client specific state over an entire session, ie a shopping cart, annotated with @Stateful.
How stateful and Stateless are deployed…
When EJBs are deployed the EJB container creates a number of instances (EJB pool), a client obtained an instance from pool, if the ran is stateful it’s state is maintained over multiple EJB method calls, if Stateless no state is maintained and the server may even use a different instance from pool next time.
Three things needed to program a bean:
A Java class which contains bean functionality, a business interface which defines those bean methods accessible to client, and annotation of the class an interface to tell server they should become EJBs.