Sunday, March 30, 2014

What is JDBC RowSet ?

A RowSet ( javax.sql.RowSet ) is an object that encapsulates a set of rows from either Java Database Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet. RowSets support component-based development models like JavaBeans, with a standard set of properties and an event notification mechanism.

Interfaces that extends RowSet are  :
  • JdbcRowSet
  • CachedRowSet
  • WebRowSet
  • JoinRowSet
  • FilteredRowSet

Benefits :
Beside sharing the capabilities of a ResultSet , RowSet adds the following new capabilities :

1.  Function as JavaBeans Component
That means RowSet objects have properties with corresponding getter and setter methods that can be exposed to builder tools (such as those that come with the IDEs JDveloper and Eclipse) that provides the capability to visually manipulate the beans.

In addition , RowSet objects use the JavaBeans event model, in which registered components are notified when certain events occur. The events that trigger notifications are :
  • A cursor movement
  • The update, insertion, or deletion of a row
  • A change to the entire RowSet contents

2.  Add Scrollability or Updatability
If a database driver does not have the ability to scroll or update result sets, RowSet object can be used for the same . A RowSet object is scrollable and updatable by default, so by populating a RowSet object with the contents of a result set, you can effectively make the result set scrollable and updatable.


Types of Rowset :
There are two types of RowSet :
  • Connected - A connected RowSet object connects to the database once and remains connected until the application terminates. Only one of the standard RowSet implementations is a connected RowSet object - JdbcRowSet.
  • Disconnected - A disconnected RowSet object connects to the database, executes a query to retrieve the data from the database and then closes the connection. A program may change the data in a disconnected RowSet while it is disconnected. Modified data can be updated in the database after a disconnected RowSet reestablishes the connection with the database.Disconnected RowSet objects are lightweight and  serializable, and it makes them ideal for sending data over a network. They can even be used for sending data to thin clients such as PDAs and mobile phones.

Saturday, March 29, 2014

How to run a standalone OSGi server

This post shows how to run Equinox as an OSGi stand-alone runtime.

Download org.eclipse.osgi_.jar from here. The same jar exists in eclipse installation directory ( plugin folder ). Copy the jar and paste into a new directory.
Example - C:\osgi\org.eclipse.osgi_3.9.1.v20140110-1610.jar

Starting the OSGi server :
java -jar org.eclipse.osgi_3.9.1.v20140110-1610.jar -console                                                                                                                
starting osgi server

Basic commands to start with :
  • install - Installs the bundle from the given URL
  • start - Starts the bundle with the given numeric or symbolic id.
  • stop - Stops the bundle with the given numeric or symbolic id.
  • ss - Reports a summary status of all installed bundles
  • diag - Reports any resolution problems for the bundle with the given numeric or symbolic id.

Understanding the JDBC architecture.

The JDBC API uses a driver manager and database-specific drivers to provide transparent connectivity to heterogeneous databases.

The JDBC driver manager ensures that the correct driver is used to access each data source.



      
The JDBC Architecture consists of two layers:
  • The JDBC API , which provides the application-to-JDBC Driver Manager connection.
  • The JDBC Driver API , which supports the JDBC Manager-to-Driver Connection.

JDBC Architecture