Friday, February 9, 2007

Container-Managed vs Bean-Managed Persistence

1. speed. You can avoid some of the unnecessary container initialized databases calls, if you use BMP's
2. In CMP, the developer uses the deployment descriptor to tell the container which attributes of the entity bean to persist.

Bean-Managed persistence gives the developer explicit control of the management of a bean instance's state.

The main advantage of BMP is Database Acess Flexbility ,

LOng back i read that BMP has acts as an interface to complex legacy SQL databases via JDBC and also enterprise data sources such as CICS, MQ-Series e.t.c.,

Disadvantage of BMP is writing the hard program for all callback
methods by us ..

3. For example with BMP, it takes two SQL stements to load an entity bean. the first call- a finder method ( loading only the primary key ) and a second, during ejbLoad() to load the actual data. A collection of n BMP requires n+1 database calls to load that data.(one finder to find a collection of primary keys, and then n loads).

With CMP, the container can reduce the n+1 database calls to a single call, by performing one giant SELECT statement. You set this up using container specific flags."

You can refer "Matering Enterprise Java Beans" second edition Ed Roman.

The container cannot do the same sort of sql optimization for BMPs for the simple reason that the
container has no control over the sqls. One of the main disadvanteges of CMP is that you can'tcall Stored Procedure from CMP.

will go for BMP in the following cases:

1.My persistent data is in non-RDBMS and the EJB container does not
support this.
2.The database schema does not map exactly to Entity fields.
3.For better performance I would like to use Stored procedure.
4.I want to manage relationship between entities for which I need to
use BMP (This is solved by using EJB 2.0 but for preEJB 2.0...)
5.I have my data from different tables or databases.


SOURCE : www.referjava.com

what are some of the java utilities that you cannot use in EJBs?

awt,I/O,sockets and multithreading.


Entity beans www.referjava.com

Entity beans and Entity beans Performance?

Entity beans are more costly then Session beans for one simple reason that Entity beans are special types of Session beans(Entity beans are build over session beans). One point to note is that Entity beans never store any state like statefull beans (They are database persistant and not memory persistant like StateFull beans). For every call or for any update or for any operation it will query the database. Now again there are two considerations in entity beans, CMP and BMP. A project coded using Session beans will any time perform better then BMP's. So the level of performance can be listed in the order of best to worse (in case of database operations)
1.Entity beans 2.BMPs 3.CMPs
U may consider this before u make any decision. In one of my project we had to drop the CMP design at the last moment because of the speed consideration. Entity type beans are ment as a better s/w design practice and not ment for a better performance. You should consider a tradeof, may be by using BMP's.


Entity beans www.referjava.com

Difference between javabeans and ejb?

JavaBeans components are small-grained application bits. You can use JavaBeans to assemble larger-grained components or to build entire applications. JavaBeans, however, are development components and are not deployable components. You typically do not deploy a JavaBean because a JavaBean is not a complete application; rather, JavaBeans help you construct larger software that is deployable. And because they cannot be deployed, JavaBeans do not need a runtime environment in which to live. JavaBeans do not need a container to instantiate
them, to destroy them, and to provide other services to them because the application itself is made up of JavaBeans. By way of comparison
The Enterprise JavaBeans (EJB) standard defines a component architecture for deployable components called enterprise beans. Enterprise beans are larger, coarser-grained application components that are ready to be deployed. They can be deployed as is, or they can be assembled with other components into larger application
systems. Deployable components must be deployed in a container that provides runtime services to the components, such as services to instantiate components as needed.


SOURCE : www.referjava.com

Web Server and Application Server

Webserver is for hosting ur webapplications (Servlets and jsps). Application
server is server which provides services like transactions, security,messaging, and other j2ee services like jndi etc to the application. Theapplications can be built using ejb which use all the declarative services,which minimizes the lines of code and reduces the application development time.

WebServer is a service or a daemon running at a given IP and a Port that is capable of accepting and responding to all HTTP events. It is created to understand the HTTP transfer protocol. The basic functionality of a WebServer is to accept a browser request for HTML pages and respond it with the resources in it. To completely understand a webserver, i will suggest, write your own webserver. Dont get scared. Writting a webserver using java is no big deal.
Creating your own WebServer
* Create a Server Socket using the ServerSocket class.
* Configure it to accept requests at a default HTTP port that is port 80.
* Once a connection is established and a request is send, read the HTTP header in the request.
* From the HTTP header, do normal parsing using StringTokenizer, and you can get the filename that is requested.
* Once u get the filename, open a filestream and read the file into some DataOutputStream object.
* Write this object over the open connection.
* Now Flush the data.
This is the most basic HTTP server that can be written in JAVA. I did this long time back, let me know if you require code, i ll try finding it in my old backups.
Over this basic functionality you can build a better and powefull WebServer.
For instance you can start with using threads to support more requests. You can set unset session id to track Sessions. You can Read the MIME type in the header to respond to various file formats like JPEG, MPEG, GIF etc. And other things. So now you understand what a web server is.
A WebServer is a service running on some remote machine that can communicate with your webBrowser and fetch you files using HTTP protocol.
And thats it, nothing more nothing less. For instance IIS and Apache are webServers. Though they do many other things then serving webpages. But that is not a part of a simple webServer.
Applicatin server.
Anything u know abt app servers minus the defn of the web server that i just stated is the job of an application server. An application server executes an application code written in some language and bundles the results in form of HTTP response, which can be send over wire by the HTTP Web Server. (Dont get confused). For instance IIS is a combination of both application server as well as web server. The webserver part is supposed to deal with the browser sending and receiving request and response objects using the HTTP protocol. The application server is responsible of doing all the processing work, executing scripts, accessing the database, bla bla.. Today's Application servers evolved long way back from there ancistors -> CGI or common gateway interface. Though CGI are not true app server as per todays defn of application servers, but it provides a backbone for the application technology that is build in the middleware.
So to make the discussion short, lets define application server
An Application server is a service or daemon running on some remote machine that communicates with the WebServer using HTTP protocol and hosts a range of services and applications. Not to explain, these services can be anything like ACLs, Object pooling, Transaction management, etc etc.
A noteworthy difference betn the two is webservers communicate with the Browser, where as app server communicate with the webServers. Here u can very well question "but y so" ?
The ans is simple. Let me give you one eg, and things will be clear.
In 1 of my project we had the following congifuration. We used the Weblogic server, providing its service at 7001 port. This is where our application(JSP, EJB, Servlets etc etc) was hosted. Then we had a IIS server providing service on 80 port. So if i connect http:\\www.mysite.com\index.html, the index.html page will be served directly by the IIS server. Now we had a configuration in IIS server which stated that all the application related requests be directed to the WebLogic server. So wheneveer IIS gets a request asking for *.jsp, *.class (say http:\\www.mysite.com\index.jsp) it gets routed to WebLogic app server. WL will get the request object, execute the script, create the response object and dump it back to IIS. IIS will wait till it receives a response from WL or till timeout occurs. On response it will just fwd it to the browser.
This architecture clearly differentiates the app server from the web server. Most of the app servers also bundle a webserver with them. That is, they behave as a single web+app server. So we dont understand the difference betwn the dual role. (above architecture is used in many scenarios, but detailed explaination is out of the scope of this discussion.)
One last thing. we can summarize by saying that serving files is the job of an webserver. And serving appliactions is the job of app server. Remember, we can access the application sevices without using the HTTP protocol. HTTP protocol was specifically created for web servers. If you have used WebLogic, there is something called as T3 services. This is the application protocol that gives you access directly to the app server services. We had an application that accessed WL directly using t3 to get the job done. (again detailed explaination of t3 or app protocols is out of the scope of this discussion).


SOURCE : www.referjava.com

What is MultiPooling?

Muli pool is nothing but pool of connection pools. WEBLOGIC server provides multipool facility


SOURCE : www.referjava.com

What's a Naming System or Service?

A naming system associates names with addresses. A phone book is a perfect example of a naming system that associate people's names with phone numbers and addresses. Naming systems are used in computing to make it easier for user to locate and utilize software that is addressable. A software system that exposes a naming system to other software is called a naming service.


SOURCE : www.referjava.com