jump to navigation

EJB 2.0 vs 3.0 January 25, 2008

Posted by Coolguy in J2EE, Java.
Tags:
add a comment
  • Entity beans retire.  Come Java persistence API
  • Deployment descriptors retire. Come annotations
  • JNDI lookups are no longer necessary
  • Simple POJO components
  • Less classes and interfaces
Advertisements

EJB Lifecycle January 25, 2008

Posted by Coolguy in J2EE, Java.
Tags:
add a comment

Stateful Session bean:

  • setSessionContext
  • Client calls create. Container calls ejbCreate
  • ejbPassivate
  • ejbActivate
  • Client calls remove. Container calls ejbRemove

Stateless Session bean:

  • ejbCreate
  • setSessionContext
  •  <<Invoke business methods>>
  • Container calls ejbRemove

Entity beans:

  • setEntityContext
  • ejbCreate
  • ejbPostCreate
  • ejbActivate
  • ejbPassivate
  • ejbRemove
  • unsetEntityContext

Message Driven beans:

  • setMessageDrivenContext
  • ejbCreate
  • ejbRemove

Stateful vs Stateless Session beans-Differences January 25, 2008

Posted by Coolguy in J2EE, Java.
Tags:
add a comment

State: Stateful maintains information across sessions while stateless doesn’t. If a transaction would span over two or more bean executions you should use stateful session bean, otherwise use stateless session bean. Stateful beans remember state between

    Scalability: Stateful beans hurt scalability.

    Pooling: Stateless beans, by nature, need not know their clients once the remote business method returns. These beans can therefore be bean-pooled. On the other hand stateful session beans may be requested back(with previous state) by a client using the javax.ejb.Handle reference that the client may have retained. In this case, the bean will need to be re-instated entirely. These beans therefore can only be instance-pooled and never shared between clients.

    Passivation: Stateless  beans are not passivated. SFSB’s are activated/passivated.

      Version 2.X:

      In ejb-jar.xml ‘session-type’ attribute determines whether the bean is stateful or stateless.

      <session-type>Stateless</session-type>

      Version 3.X

      Stateful beans import: import javax.ejb.Stateful

      Stateless beans import: import javax.ejb.Stateless

      Stateful Session Beans – Best practices January 25, 2008

      Posted by Coolguy in J2EE, Java.
      Tags:
      add a comment

      Stateful Session EJB is a server-side object designed to hold data on behalf of a particular client.

      SFSBs should be used to store session-oriented data. They hold the data on behalf of the client. Session-oriented data is used to track a multi-request sequence, ordering, or any associated data that is part of a sequence.

      SFSBs, however, have a limited lifespan and are not intended to survive server crashes. Although SFSBs are allowed to access a database and load data into memory, but the act of caching persistent data lies within the responsibilities of entity beans.

      The EJB specification suggests that a shopping cart for an e-commerce system could be implemented with SFSBs. This is perfectly acceptable if that shopping cart is only intended to be an in-memory implementation that does not need to survive a server crash. In reality, however, most implementations of shopping carts are required to survive server crashes; the data contained within the shopping cart needs to be persistent and transactional — with an in-memory data cache. i:e Using entity beans.

      When to use them ? 

      In very few J2EE systems !!

      Systems that have JSP/servlet front-ends should use HttpSession objects to store session-oriented state. Using both  HttpSession and SFSB is simply duplicating the effort.

      For systems that do not have a servlet/JSP front-end, SFSBs should be used to track session-oriented state similar to the way a web-based system would use an HttpSession object.

      Use SFSB’s along with  HttpSession when:

      Your app server doesn’t offer caching of HttpSession objects. This will mean that you may have to have to limit on number of sessions.  Using SFSB’s in this scenario will increase scalability as a  container can activate/passivate SFSB’s as needed.

      Data mapper January 22, 2008

      Posted by Coolguy in Java, Java Frameworks.
      Tags:
      add a comment

      Data mapper moves the data between objects and database keeping them independent of each other.

      With Data Mapper the in-memory objects needn’t know even that there’s a database present; they need no SQL interface code, and certainly no knowledge of the database schema

      Active record January 22, 2008

      Posted by Coolguy in Java, Java Frameworks.
      Tags:
      add a comment

      An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data.

      Application Tiers & Testing Frameworks September 7, 2005

      Posted by Coolguy in Testing.
      add a comment

      Approach to testing September 7, 2005

      Posted by Coolguy in Testing.
      add a comment

      Testing approach follows the following processes:

      • Unit Testing: JUnit
      • Integration Testing
      • System Testing
      • User Acceptance Testing
      • Performance testing : JMeter

      Attributes August 24, 2005

      Posted by Coolguy in Servlets/Jsp.
      add a comment
      • Attribute is a object bound to other servlet API objects like ServletContext,HttpServletRequest,HttpSession
      • Types:
        Application
        Request
        Session
      • To set an attribute :
        setAttribute(String name,Object value)
      • Method to get:
        getAttribute(String name)
      • Return type:
        Object
      • Scope of attribute:
        Context,
        Session ,
        Request
      • Three attribute scopes Context,Session,Request are handled by ServletContext,ServletRequest,HttpSession interfaces
      • Methods are:
        getAttribute(String)
        setAttribute(String,Object)
        removeAttribute(String)
        getAttributeNames()
      • Context scope attributes are not thread-safe
      • Session scope attributes are not thread-safe as its one thread per request not one per session.
      • To make them thread safe synchronize ServletContext and HttpSession respectively
      • Request variables and local variables are thread safe
      • Instance variables are also not thread safe

      Servlet Listeners August 24, 2005

      Posted by Coolguy in Servlets/Jsp.
      add a comment
      • Attribute added,removed or replaced: ServletContextAttributeListener
      • Tracking active sessions: HttpSessionListener
      • Log each request: ServletRequestListener
      • Request attribute added,removed or replaced: ServletRequestAttributeListener
      • Attributes added to session: HttpSessionBindingListener
      • Session attribute added,removed or replaced: HttpSessionAttributeListener
      • Context created or destroyed: ServletContextListener
      • Attributes notified when the session is migrating to another JVM:HttpSessionActivationListener


      HttpSessionAttributeListener

      • This class knows when any type of attribute has been added,removed or replaced in a session


      HttpSessionBindingListener

      • Attribute itself can find out when it has been added to or removed from a session
      • E.g:
        import javax.servlet.http.*;public class Dog implements HttpSessionBindingListener
        {
        private String breed;

        public Dog(String breed)
        {
        this.breed=breed;
        }
        public String getBreed()
        {
        return breed;
        }
        public void valueBound(HttpSessionBindingEvent arg0)
        {
        // TODO Auto-generated method stub
        }
        public void valueUnbound(HttpSessionBindingEvent arg0)
        {
        // TODO Auto-generated method stub
        }
        }