ServicesTabVWPDatasourceConsumer

Visual Web Consumer of Database Connection from Services Tab

Modificaion History
Winston Prakash: Feb 8, 2007


Note: This is just sample or a starter document to start the discussion based on Services Tab Architecture. Does not correctly reflect the implementation details. Need to be re-written by the Service Type implementor. - Winston

This document applies only to VWP designer - Winston


Contents



Introduction

This document explains how the Visual Web Pack Service Consumer would consume a Database Table (or a View) once it is Drag and Dropped from a Database Connections Node. VWP web page designer (here after just designer) is the primary receiving agent of the Drag and Drop. It could consume it directly or delegate the task to a Helper.

Database Table Consumer

VWP web page designer could extract the Database Connection info from the DnD using the public Contract defined in the Database Connections Public Contracts document. Instead it delegates the actual consumption task to a helper module. For database table consumption the task is delegated to the dataconnectivity module, which we would refer as Database Consumer Helper.

Let us see an example on how the designer would consume the Database Table dropped on to it. The only consumable object designer understands is BeanCreateInfoSet (a generic definition of consumable object holder defined by the VWP Design Time System). The designer could implement the required code to convert the DnD to an BeanCreateInfoSet. That means designer needs to understand the DnD contract defined by Database Connections manager.

However, the preferred solution would be to use the Consumer Helper and pass on the DnD Transferable to it. The Consumer Helper would take the DnD and creates the BeanCreateInfoSet and gives it back to the designer. The advantage of this approach is, designer need not have to know about the DnD Contract nor the Service Meta data Contract to convert the DnD Transferable to a consumable object, but relies on the Consumer Helper to do the job.


Database Table Consumer Helper

Since there can be multiple Consumer Helper modules to help consume DnD from Nodes of different Services in the Services Tab, then designer need to interact with each of these Helpers, thus creating module dependencies. Since VWP Design Time System defines a single wrapper consumable object, designer could provide a public SPI for these helpers and then relies on NB lookup mechanism to get the implementors of this SPI. Out of the several possible Helpers, only one will understand the DnD transferable corresponding to Database Table. One such Helper would be implemented in the

Here is an Example interface that would be defined by the VWP designer

public interface DesignTimeTransferDataCreator {
    /** Gets <code>DisplayItem</code> for specified <code>Transferable</code>
     * @return <code>DisplayItem</code> or <code>null</code> */
    public DisplayItem getDisplayItem(Transferable transferable);
}

Note: DisplayItem is a super interface of BeanCreateInfoSet.

The Dataconnectivity Module can implement the VWP specific Service Helper and register it


public class DatasourceTransferManager implements DesignTimeTransferDataCreator{

    public DisplayItem getDisplayItem(Transferable transferable) {
        Object transferData = null;
        try {
            DataFlavor supportedFlavor = DatabaseMetaDataTransfer.TABLE_FLAVOR;
            if (transferable.isDataFlavorSupported(supportedFlavor)){
                transferData = transferable.getTransferData(supportedFlavor);
                if(transferData != null){
                    if(transferData.getClass().isAssignableFrom(DatabaseMetaDataTransfer.Table.class)){
                        DatabaseMetaDataTransfer.Table tableInfo = (DatabaseMetaDataTransfer.Table) transferData;
                        String schemaName = tableInfo.getDatabaseConnection().getSchema();
                        String tableName =
                            ((schemaName == null) || (schemaName.equals(""))) ?
                            tableInfo.getTableName() :
                            schemaName + "." + tableInfo.getTableName();
                        // String tableName = tableInfo.getTableName();
                        DatabaseConnection dbConnection = (DatabaseConnection)tableInfo.getDatabaseConnection();
                        JDBCDriver jdbcDriver = (JDBCDriver) tableInfo.getJDBCDriver();

                        // Create the Bean Create Infoset and return
                        return new DatasourceBeanCreateInfoSet(dbConnection, jdbcDriver, tableName);
                    }
                }
            }
        }catch (Exception exc) {
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
        }
        return null;
    }


Note that, this Consumer Helper get the Database Connection information via the Database Connection Metadata Contract published by the Database Connection manager.


When we DnD a data table three level of DataSources and the corresponding JNDI name are considered.

- Data source already existing in the Server (Server Data Source) - Data source existing in the Project as meta data, which is not yet deployed (Project Data Source) - Data Source in the IDE data source model (IDE data Source)

When the table is DnD from the NB database explorer node, a DataSource is added to the IDE DataSource model. This is needed for the design time connection to work. Then the DataSource information is written to the project meta data and then at deploy time a Sever DataSource is created.

Note: First the DataSource information is kept in the project meta data and then at deploy time, a Sever DataSource is created. However, if the DataSource (with the same name) exists in the server, then project meta data is not written (this has a problem which I discussed below)

This DataSource we add need a proper JNDI name for it. Also it should consider if the DataSource already exist in the project meta data or in the Server. So the name is computed using the following logic

- First get the following information from the Transferable from NB database explorer node

  - JDBC connection URL
  -  JDBC driver class
  - User Name
  - Password

- Based on the above information, search the existing data sources and collect the separate sets of DataSources from IDE and Project and/or Server. Since the project data source is what get deployed eventually we use that set collectively.

Now we have four scenarios

1. No matching IDE data sources or Project/Server data sources found - Simply create a data source in the IDE with name "datasource" and add it to the project.

       JNDI name used in the code  is that of  the newly added DataSource

2. No matching IDE data source found but found in the Project/Server DataSources.

   - Create the datasource in the IDE using the JNDI name of Project/Server datasource.
      (First data source in the set is used).
   - Add to project action is not performed.
   - JNDI name of the Project/Server datasource is used in the source code.

3. IDE DataSource found but no project/server DataSource found.

     - Use the JNDI name of the first DataSource in the set for the code
     - Add that DataSource to the project meta data, which will be eventually deployed

4. Both IDE DataSources and Project/Server DataSources found, so we use the following logic

     - Loop through the set of  Project/Server DataSources and see if matching JNDI name in the set of
        DataSources from the IDE.  If found use the JNDI name of that DataSource in the code
     - If  JNDI name corresponding to Project/Server datasource is not found in the IDE DataSources,
        then add a new DataSource to the IDE with the same name as that of the first Project/Server DataSources.

As I mentioned above, there is one problem still exists. - Assume no data sources in the project but only in the server. DnD the table will work at design time and at deployment time as the data source from the server will be added to the IDE DataSources while DnD the table. - Now in the project switch to another server with out the DataSource and deploy. Design time will work but deployment time will fail as there are no DataSource in the server.


Once the Data Source created from the Database Connection information is added to the project. The details are covered in the documentation VWP DataSource Integration.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo