-EJB Entity Beans are very fat. That?s why we will go for spring and Hibernate which are light weight compared to EJB.
-EJB Entity Beans work only inside of EJB Containers like JBoss, WebLogic, and WebSphere. But Hibernate can be used for Java Applications also. That means we can use hibernate outside of EJB Container also.
Hibernate is high performant compared to entity beans and hibernate uses two levels of cache which stores results in this cache, if same request comes, it will not hit the database, but fetches data from cache thus improves the performance.
The basic approach is similar: it is possible to specify transaction behavior (or lack of it) down to individual method level. It is possible to make a setRollbackOnly() call within a transaction context if necessary. The differences are:
Unlike EJB CMT, which is tied to JTA, the Spring Framework's declarative transaction management works in any environment. It can work with JDBC, JDO, Hibernate or other transactions under the covers, with configuration changes only.
EJB (Enterprise Java Beans)is standard for building server side component in Java.
It specifies an agreement between components and application server that enables any application to run on any application server.
Following are the different kind of EJBs:
Message Driven beans.
Session beans are of two types:
Stateless session beans : These beans do not maintain state across method calls.
Stateful session beans : These beans hold client state across method invocations.
Using Session beans you can create highly scalable and secured enterprise application using object pooling techniques.
Message driven beans can be used for receiving messages from different systems.
Using Message driven beans you can create a highly scalable listener which can read messages and process accordingly.
EJB (Enterprise Java Beans)is standard for building server side component in Java. It specifies an agreement between components and application server that enables any application to run on any application server.
Following are the different kind of EJBs:
Message Driven beans.
There are 6 Transactional Attributes are there.
Spring comprises of seven modules. They are..
The core container:
The core container provides the essential functionality of the Spring framework. A primary component of the core container is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specification from the actual application code.
The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality.
The Spring AOP module integrates aspect-oriented programming functionality directly into the Spring framework, through its configuration management feature. As a result you can easily AOP-enable any object managed by the Spring framework. The Spring AOP module provides transaction management services for objects in any Spring-based application. With Spring AOP you can incorporate declarative transaction management into your applications without relying on EJB components.
The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write, such as opening and closing connections. Spring DAO's JDBC-oriented exceptions comply to its generic DAO exception hierarchy.
The Spring framework plugs into several ORM frameworks to provide its Object Relational tool, including JDO, Hibernate, and iBatis SQL Maps. All of these comply to Spring's generic transaction and DAO exception hierarchies.
Spring Web module:
The Web context module builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.
Spring MVC framework:
The Model-View-Controller (MVC) framework is a full-featured MVC implementation for building Web applications. The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, and POI.
Facade means the principal front of a building, that faces on to a street or open space.
Facade pattern abstracts the complexities of the system.
Facade pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. This type of design pattern comes under structural pattern as this pattern adds an interface to existing system to hide its complexities.
This pattern involves a single class which provides simplified methods required by client and delegates calls to methods of existing system classes.
Facade is a structural design pattern that provides a simplified (but limited) interface to a complex system of classes, library or framework. While Facade decreases the overall complexity of the application, it also helps to move unwanted dependencies to one place.
Session facade is one design pattern that is often used while developing enterprise applications. It is implemented as a higher level component (i.e.: Session EJB), and it contains all the iteractions between low level components (i.e.: Entity EJB).
Connection Pooling in Struts :
In struts-config.xml file data sources tag is there? you can configure connection pool from that xml file and you can create the connection as below.
<set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
<set-property property="url" value="jdbc:mysql://localhost/DBNAME" />
<set-property property="username" value="" />
<set-property property="password" value="abcdefgh" />
<set-property property="maxActive" value="20" />
<set-property property="maxWait" value="5000" />
<set-property property="defaultAutoCommit" value="false" />
<set-property property="defaultReadOnly" value="false" />
...//Here Other Struts Configuration Tags...
In the above file the default values comes with this file was maxActive 20.
You can set the values here as per your network traffic on your server?
Here totally 20 connection objects will be active in the pool and 5000 (5 seconds ) will be the time to wait for a connection object. You can set number of maxIdle connections also.
CODE : in your Action Class execute method or any other class you can create the connection object like this.
//Just declare the data source and connection objects;
javax.sql.DataSource dataSource = null;
java.sql.Connection myConnection = null;
//Just by using the following 2 lines of Code you can create a connection //object from the data source by using the concept of connection pooling.
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
You can also refer to EJB Instance Pooling...
How do you configure data source in Tomcat ?
How do you configure data source in WebLogic ?
How do you configure data source in JBoss ?
How do you configure data source in WebSphere ?
Ads By Google
© 2018 - JavaSpartans.com • All Rights Reserved