Your SlideShare is downloading. ×
0
Whats new in EJB 3.1?                             a.k.a                 How do I convert      my POJOs to EJBs with JEE6
What Im gonna talk about●   What is EJB 3.1●   Whats new on EJB 3.1●   Types of EJB 3.1    –   Stateless    –   Stateful  ...
What this session is NOT about●   Full JEE6 stack●   Persistence with EJB●   Transactions●   JMS●   NOT about EJB but you ...
What is EJB 3.1●   A whole new simplified way of developing enterprise    applications which follows JEE specification.●  ...
Whats new on EJB 3.1●   Requires NO framework specific API to be    extended or realized●   Efficient use of Annotations f...
Stateless Beanpublic class CalculatorBean {    public int add(int a, int b) {        return a + b;    }    public int subt...
Stateless Bean@statelesspublic class CalculatorBean {    public int add(int a, int b) {        return a + b;    }    publi...
Stateful Beanspublic class Counter {    private int count = 0;    public int count() {        return count;    }    public...
Stateful Beans@statefulpublic class Counter {    private int count = 0;    public int count() {        return count;    } ...
Singleton Beans@singletonpublic class PropertyRegistry {    private final Properties properties = new Properties();    pub...
Bootstrapping Beans on “startup”@singleton@startuppublic class PropertyRegistry {    private final Properties properties =...
Injecting EJB to another@statelesspublic class AuthenticationBean {    @EJB    private LoginBean loginBean;    public void...
Exposing EJB as REST@Singleton@Lock(LockType.WRITE)@Path("/user")@Produces(MediaType.APPLICATION_XML)public class UserServ...
JUnit tesing EJBspublic class CalculatorTest extends TestCase {   private CalculatorBean calculator;   protected void setU...
Upcoming SlideShare
Loading in...5
×

Ejb3.1

779

Published on

new features of EJB3.1

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
779
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Ejb3.1"

  1. 1. Whats new in EJB 3.1? a.k.a How do I convert my POJOs to EJBs with JEE6
  2. 2. What Im gonna talk about● What is EJB 3.1● Whats new on EJB 3.1● Types of EJB 3.1 – Stateless – Stateful – Singleton● Other aspects of EJB 3.1 – Injecting beans in to another EJB – Exposing EJB as REST● Unit testing EJB
  3. 3. What this session is NOT about● Full JEE6 stack● Persistence with EJB● Transactions● JMS● NOT about EJB but you I ll let u know about EJB ;-)
  4. 4. What is EJB 3.1● A whole new simplified way of developing enterprise applications which follows JEE specification.● “whole new simplified” -> just POJO no framework specific API needs to extended or realized always. EJB == JB (the “E” factor is taken care by the container)● Unit test without pain !!
  5. 5. Whats new on EJB 3.1● Requires NO framework specific API to be extended or realized● Efficient use of Annotations for developing beans● No vendor specific deployment descriptors needed● New annotations to develop beans such as – Singleton – Startup – Timer & schedule expressions – Exposing EJB as REST services
  6. 6. Stateless Beanpublic class CalculatorBean { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; }}
  7. 7. Stateless Bean@statelesspublic class CalculatorBean { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; }}
  8. 8. Stateful Beanspublic class Counter { private int count = 0; public int count() { return count; } public int increment() { return ++count; }}
  9. 9. Stateful Beans@statefulpublic class Counter { private int count = 0; public int count() { return count; } public int increment() { return ++count; }}
  10. 10. Singleton Beans@singletonpublic class PropertyRegistry { private final Properties properties = new Properties(); public String getProperty(String key) { return properties.getProperty(key); } public String setProperty(String key, String value) { return (String) properties.setProperty(key, value); } public String removeProperty(String key) { return (String) properties.remove(key); }}
  11. 11. Bootstrapping Beans on “startup”@singleton@startuppublic class PropertyRegistry { private final Properties properties = new Properties(); public String getProperty(String key) { return properties.getProperty(key); } public String setProperty(String key, String value) { return (String) properties.setProperty(key, value); } public String removeProperty(String key) { return (String) properties.remove(key); }}
  12. 12. Injecting EJB to another@statelesspublic class AuthenticationBean { @EJB private LoginBean loginBean; public void doLogin() { LoginBean.authenticate(); // ... }}
  13. 13. Exposing EJB as REST@Singleton@Lock(LockType.WRITE)@Path("/user")@Produces(MediaType.APPLICATION_XML)public class UserService { @Path("/list") @GET public List<User> list() { // .... return users; }}
  14. 14. JUnit tesing EJBspublic class CalculatorTest extends TestCase { private CalculatorBean calculator; protected void setUp() throws Exception { EJBContainer ejbContainer =EJBContainer.createEJBContainer(); Object object =ejbContainer.getContext().lookup("java:global/simple-stateless/CalculatorBean"); assertTrue(object instanceof CalculatorBean); calculator = (CalculatorBean) object; } public void testAdd() { assertEquals(10, calculator.add(4, 6)); }
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×