Rowset is a Java-Bean Compliant Object that Encapsulates Database Access.
In Rowset we only have to create a single object rather than the typical 3 objects - Connection(for creating connection), Statement(for query execution), ResultSet (to get the Result).
Apart from this encapsulation Rowset object can be used as a java-bean component. As a bean, a rowset provides a set of mutators for setting properties and a complementary set of accessors to get the values of these properties. Rowset also supports JAVABEAN style events. Rowset object generates events when certain changes occurs in the state of the Rowset. Interested objects can register themselves as listeners for these events and be notified as event occurs[provide event listeners like AWT & Swings].
Rwset.setCommand(“sql”);
Rwset.setURl(“ ”);
Rwset.setUserName(“”);
Rwset.setPassWord(“”);
Rwset.execute()
Besides providing properties it also encapsulates a set of row(s) [Results].Resultset offers a wide variety of methods to access result set rows and corresponding fields.
There are 3 types of rowset objects. These are actual implementation of Rowset Interface. These implementations are not part of Core Api or JDBC Api.
- Cached Rowset
- JDBC Rowset
- Web Rowset
The JDBC Rowset is a connected approach [unless u don’t use close() method] and is not serializable.
1. Cached Rowset extends BaseRowset implements Rowset, Rowsetinternal, Cloneable, Serializable
It is a disconnected, serializable, cloneable and scrollable container for rows of data.
It is disconnected and therefore doesn’t hold a connection object. Since it is serializable and cloneable, we can create copies of our cached Rowset and transfer them across the wire. For instance an ejb component can create and return a cached rowset
to the client across the network. The client can modify the Rowset and send it back to the component and component can perform updates.
Use :
1. If client application intends to hold the connection for long time intervals.
2. Client has neither capacity nor resources for connecting to database. For instance Networked Devices such as PDAs & other thin clients do not have resources to connect to the databases. In such cases, a server side application can create a cached rowset, and send it across the network to the thin client. The client can scroll thru the rowset and may also save it for later use.the client can send a copy of the result back to the server side application whenever it updates it. In effect the cached rowset gives the ability to create a “Downlodable Resultset”. creation of cachced rowset is similar to rowset code and it also all methods of Resultset.actually updatexxx() methods are there.
CachedRowSet cr=new CachedRowSet()
Cr.setUser,pass,command
Cr.execute();
While (cr.next)
{
statements
}
Since the cached rowset is disconnected, to update the Database cr.acceptChanges() method is there. It re-establishes the connection to the database & makes the necessary updates to the database.this method throws SQLEXception in case of Failures while making changes.
2. JDBC Rowset implements Rowset
It is a connected Rowset.purpose of the jdbc Rowset is to provide a JAVABEANS type layer on top of java.sql.Resultset.unlike a cached rowset, a jdbc rowset is connected,is not serializable andnor cloneable. It provides whatever features the underlying Resultset interface provides, with the added advantage of presenting itself like a java-bean.
3. Web Rowset extends Cached Rowset
It is intended for web-based applications. It communicates with other components by the use of XML over HTTP Protocol not over TCP-IP based DATABASE protocols.
A web client (possibly with java-script or java support) retrieves a set of result(s) using webrowset Object. When the webrowset object’s execute method is called, it calls a servlet on the server-side (which performs database access) to populate the resultset.once the rowset is updated , the webrowset object sends the updated data to a server side implementation of the rowset as xmldata over HTTP Protocol. The server side implementation then updates the database. Webrowset objects use incremental caching of data.so that data can be retrieved in chunks.as the client browses thru the webrowset,additional data is downloaded from the server side.
When the web client creates a webrowset and executes a command,the client side implementation of webrowset send this request to the server side implementation of over HTTP.The server side implementation would connect to the database, execute the command and populate the Rowset. The server side implementation would then write the data in to an xml document & sends it back to the client implementation over HTTP. This process is repeated when client modifies the rowset and call AcceptChanges. The client side implementation would send an xml copy of the webrowset to the server side implementation over HTTP and the server side implementation would perform actual updates.
Using the WebRowset eliminates the need for the client to connect to the database server on the internet.if there is a facility to connect to the database sever from client (however proxies & fire walls allow this) there will be a security threat.in order to avoid this server side implementation of webrowset Object would act as a proxy for the database.therefore client side implementation uses the server-side implementation to retrieve & update results.The main implication of this architecture is that it makes the database clients thin & clients can use the HTTP protocol [INSTEAD OF TCP-IP BASED DATABASE PROTOCOLS].
Conclusions
Actually there will be client side and server side implementation (work as a proxy for database access) which will be by default available. Whenever a client will create a WEBROWSET object and fire the execute() method on it, it will call the client side implementation(Proxy for client to access the server) of WEBROWSET object that will call the server side implementation that will actually perform the database access and render the WEBRowset and then will write data in to XML Document and send it back to the client side implementation over HTTP, and similar process will be repeated when client modifies the rowset object and call accept changes.the client side implementation would send an xml copy of the webrowset to the server-side implementation over HTTP and the server side implementation would perform actual updates.
|