Computas AS kunnskap system EJB in the real world INF5040 2007-09-27 Geir Arne Waagbø Slide 1 27.09.2007
Master s degree Computer Science, NTH 1990 PhD Mathematics, UiO 1997 Employed by Computas since 1997 Worked with Java technology since 1998 Worked with EJB since 2000 Slide 2 27.09.2007
Agenda Enterprise applications what is it? Why use an EJB-server? Java, EJB, and JEE JEE Java Enterprise Editon EJB in some detail EJB 2.1 vs EJB 3.0 Some examples Slide 3
Enterprise applications Business applications both in the private and the public sector Online shopping Order entry and billing Personnel and payroll Case handling and workflow... What is not: Embedded software Games Operating systems etc Engineering software Word processors, spreadsheets,...... Slide 4 27.09.2007
Enterprise applications Lots of persistent data Large relational database (>100GB) Lots of simultaneous users (>1000) Web clients Desktop clients OLTP Online Transaction Processing The opposite OLAP Online Analytical Processing (or BI Business Intelligence) Integration with other systems Slide 5 27.09.2007
Problems Security: All clients have database connections Web clients: sql-injection No such thing as client side security Performance Connection pooling Network Transactions Client code and business logic Integration: Let other systems use the database? Slide 7 27.09.2007
Java, EJB and JEE Java programming language In the same way as C#, C++,... Java technology platform In the same way as.net Can use other programming languages! JEE Java Enterprise Edition Slide 9 27.09.2007
JEE - Java Enterprise Edition Before it was called J2EE EJB Enterprise Java Beans API-specifications: JDBC, JMS, RMI,... Web container Servlets, JSP - Java Server Pages and JSF Java Server Faces Portlets Slide 10 27.09.2007
JEE Products JBoss (open source) IBM WebSphere BEA WebLogic Oracle Application Server (OC4J) Sun Glassfish In theory applications should be portable between products Slide 11 27.09.2007
EJB Enterprise Java Beans EJB is an API + specification EJB runtime Java VM EJB Container Current version: EJB 3.0 Slide 12 27.09.2007
Services provided by the EJB Container Remoting RMI (Remote method invocation) Transactions Persistence JNDI Java naming and directory services Security JAAS Java authentication and authorization services LDAP-integration Resource pooling Deployment Slide 13 27.09.2007
Types of EJBs Session Beans (Stateless) Remoting Transaction demarcation Can be exposed as web services Entity Beans O/R-Mapping Persistence Message Driven Beans Typically used for asynchronous interfaces Slide 14 27.09.2007
Transactions As for databases ACID Atomicity (all or nothing) Consistency (the state is consistent) Isolation (isolated from other users) Durability (the data is stored) Distributed transactions Slide 16 27.09.2007
Persistence Entity Beans - databases EJB-servers always used in conjunction with a relational database MySQL (open source) Hypersonic (bundled with JBoss) IBM DB2, Oracle, MS SQLServer Entity Beans O/R-Mapping Slide 17 27.09.2007
Connection pooling A database connection is expensive Literally! Requires lots of system resources Takes time to establish Therefore: Use a pool Closing a connection returns it to the pool The same pattern can be used for other kinds of resources as well Slide 18 27.09.2007
EJB 2.1 EJB-classes had to implement specific interfaces Deployment descriptors, xml-files that describe: Transactional properties O/R-mapping Example: EJBOrgUnitBean Slide 19 27.09.2007
EJB 3.0 Instead of deployment descriptors: Annotations No interfaces needs to be implemented Annotated POJOs can be container managed! Java Persistence API JBoss uses Hibernate to implement EJB 3.0 Example: Person Slide 20 27.09.2007
Benefits of EJB 3.0 Defaults Ease of development Can use POJOs Possible to write unit tests Can do without xml deployment descriptors Fewer artifacts Slide 21 27.09.2007
Some advice Use some caching A client needs just one JNDI-context Don t duplicate code! Getting the JNDI-context Getting a database connection Handling exceptions Use try... finally... when accessing resources Slide 22 27.09.2007