SlideShare a Scribd company logo
1 of 14
Download to read offline
Whats new in EJB 3.1?
                             a.k.a
                 How do I convert
      my POJOs to EJBs with JEE6
What I'm 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
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 ;-)
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 !!
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
Stateless Bean
public class CalculatorBean {
    public int add(int a, int b) {
        return a + b;
    }
    public int subtract(int a, int b) {
        return a - b;
    }
}
Stateless Bean
@stateless
public class CalculatorBean {
    public int add(int a, int b) {
        return a + b;
    }
    public int subtract(int a, int b) {
        return a - b;
    }
}
Stateful Beans
public class Counter {
    private int count = 0;
    public int count() {
        return count;
    }
    public int increment() {
        return ++count;
    }
}
Stateful Beans
@stateful
public class Counter {
    private int count = 0;
    public int count() {
        return count;
    }
    public int increment() {
        return ++count;
    }
}
Singleton Beans
@singleton
public 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);
    }
}
Bootstrapping Beans on “startup”
@singleton
@startup
public 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);
    }
}
Injecting EJB to another
@stateless
public class AuthenticationBean {
    @EJB
    private LoginBean loginBean;
    public void doLogin() {
    LoginBean.authenticate();
    // ...
    }
}
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;
    }
}
JUnit tesing EJBs
public 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));
   }

More Related Content

What's hot

Hipster Oriented Programming
Hipster Oriented ProgrammingHipster Oriented Programming
Hipster Oriented Programming
Jens Ravens
 
Oop lec 5-(class objects, constructor & destructor)
Oop lec 5-(class objects, constructor & destructor)Oop lec 5-(class objects, constructor & destructor)
Oop lec 5-(class objects, constructor & destructor)
Asfand Hassan
 

What's hot (20)

Mysql creating stored function
Mysql  creating stored function Mysql  creating stored function
Mysql creating stored function
 
Seasar Conference 2009 White - DI
Seasar Conference 2009 White - DISeasar Conference 2009 White - DI
Seasar Conference 2009 White - DI
 
Callback Function
Callback FunctionCallback Function
Callback Function
 
Reactjs: Rethinking UI Devel
Reactjs: Rethinking UI DevelReactjs: Rethinking UI Devel
Reactjs: Rethinking UI Devel
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
 
Js: master prototypes
Js: master prototypesJs: master prototypes
Js: master prototypes
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
JavaScript Beyond jQuery
JavaScript Beyond jQueryJavaScript Beyond jQuery
JavaScript Beyond jQuery
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Say Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android DevelopmentSay Goodbye To Java: Getting Started With Kotlin For Android Development
Say Goodbye To Java: Getting Started With Kotlin For Android Development
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Learn You a Frege for Great Good!
Learn You a Frege for Great Good!Learn You a Frege for Great Good!
Learn You a Frege for Great Good!
 
Functional patterns and techniques in C#
Functional patterns and techniques in C#Functional patterns and techniques in C#
Functional patterns and techniques in C#
 
Hipster Oriented Programming
Hipster Oriented ProgrammingHipster Oriented Programming
Hipster Oriented Programming
 
Oop lec 5-(class objects, constructor & destructor)
Oop lec 5-(class objects, constructor & destructor)Oop lec 5-(class objects, constructor & destructor)
Oop lec 5-(class objects, constructor & destructor)
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 

Similar to Ejb3.1

Software Transactioneel Geheugen
Software Transactioneel GeheugenSoftware Transactioneel Geheugen
Software Transactioneel Geheugen
Devnology
 
Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014
Antoine Sabot-Durand
 

Similar to Ejb3.1 (20)

Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 Kotlin
 
To inject or not to inject: CDI is the question
To inject or not to inject: CDI is the questionTo inject or not to inject: CDI is the question
To inject or not to inject: CDI is the question
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
 
What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 
Kotlin For Android - Constructors and Control Flow (part 2 of 7)
Kotlin For Android - Constructors and Control Flow (part 2 of 7)Kotlin For Android - Constructors and Control Flow (part 2 of 7)
Kotlin For Android - Constructors and Control Flow (part 2 of 7)
 
Software design principles SOLID
Software design principles SOLIDSoftware design principles SOLID
Software design principles SOLID
 
Software Transactioneel Geheugen
Software Transactioneel GeheugenSoftware Transactioneel Geheugen
Software Transactioneel Geheugen
 
Effective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's bookEffective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's book
 
Class 6 2ciclo
Class 6 2cicloClass 6 2ciclo
Class 6 2ciclo
 
Ejb3 Dan Hinojosa
Ejb3 Dan HinojosaEjb3 Dan Hinojosa
Ejb3 Dan Hinojosa
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 
Journey of a C# developer into Javascript
Journey of a C# developer into JavascriptJourney of a C# developer into Javascript
Journey of a C# developer into Javascript
 
OO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual FunctionOO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual Function
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
 
Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014
 

More from PrasannaKumar Sathyanarayanan

More from PrasannaKumar Sathyanarayanan (10)

Akka introtalk HyScala DEC 2016
Akka introtalk HyScala DEC 2016Akka introtalk HyScala DEC 2016
Akka introtalk HyScala DEC 2016
 
Akka fsm presentation
Akka fsm presentationAkka fsm presentation
Akka fsm presentation
 
Cps (continuation passing style) in scala
Cps (continuation passing style) in scalaCps (continuation passing style) in scala
Cps (continuation passing style) in scala
 
Introduction to akka chense
Introduction to akka   chenseIntroduction to akka   chense
Introduction to akka chense
 
Finagle - an intro to rpc & a sync programming in jvm
Finagle - an intro to rpc & a sync programming in jvmFinagle - an intro to rpc & a sync programming in jvm
Finagle - an intro to rpc & a sync programming in jvm
 
Websocket,JSON in JEE7
Websocket,JSON in JEE7Websocket,JSON in JEE7
Websocket,JSON in JEE7
 
Scala Introduction with play - for my CSS nerds
Scala Introduction with play - for my CSS nerdsScala Introduction with play - for my CSS nerds
Scala Introduction with play - for my CSS nerds
 
CDI in JEE6
CDI in JEE6CDI in JEE6
CDI in JEE6
 
Producer consumerproblem
Producer consumerproblemProducer consumerproblem
Producer consumerproblem
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Ejb3.1

  • 1. Whats new in EJB 3.1? a.k.a How do I convert my POJOs to EJBs with JEE6
  • 2. What I'm 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. 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. 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. 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. Stateless Bean public class CalculatorBean { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; } }
  • 7. Stateless Bean @stateless public class CalculatorBean { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; } }
  • 8. Stateful Beans public class Counter { private int count = 0; public int count() { return count; } public int increment() { return ++count; } }
  • 9. Stateful Beans @stateful public class Counter { private int count = 0; public int count() { return count; } public int increment() { return ++count; } }
  • 10. Singleton Beans @singleton public 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. Bootstrapping Beans on “startup” @singleton @startup public 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. Injecting EJB to another @stateless public class AuthenticationBean { @EJB private LoginBean loginBean; public void doLogin() { LoginBean.authenticate(); // ... } }
  • 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. JUnit tesing EJBs public 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)); }