Friday Sep 07, 2007

Well, it's been awhile.  I've been busy implementing new database features for the Visual Web framework for NetBeans 6.0 .  We're getting close to releasing a Beta.  There might be another Beta release to try to fix some bugs found by Customers.  In this entry (an update to Data sources in Visual Web Pack)I'll discuss the feature to help recover or resolve database connections.   Since database connection references are stored in the userdir, if a project is moved from one system to another or a user deletes their userdir the references are also deleted.  For Visual Web projects that use databases, connections must be available and known to NetBeans.  The feature described below helps a user restore database connection references.

 
Now that integration of database functionality has been more tightly integrated since 5.5, I had to re-do this feature.  There is a little bit of documentation in inline help for 5.5.  Hopefully this entry explains this feature better.

A visualweb project that contains database rowset bindings has an associated datasource for each rowset bundled in the project.
If a project is moved to another machine or the userdir was deleted (drivers and connections are lost) then at design-time, bindings to the
rowsets will fail such that when a visualweb page is opened, a Component Error window opens instead of the expected page design.
Since visualweb requires live connections to the database at design-time, each project data source must have a corresponding connection, this Resolve Broken Data Sources will help the user restore the driver and or connection.

Also, if a project is migrated from Java Studio Creator 2 then
the project datasources are restored within the project (the driver and connection are migrated when migrating the userdir settings from Creator 2)

In Creator 2, users could create data sources using the Data Sources node in the Server Navigator. Also, there was a facility to import/export datasources used by the IDE (by saving datasources used a config file) when migrating projects, whether from release to release or machine to machine.

 
In VWP 5.5, the Server Navigator was removed for the sake of redundancy with the Services window. The Services window is where Application Servers, Database connections and EJB clients are registered.

 
Feature summary

This feature's purpose is to detect when database connections, needed by a visualweb database project, have not been registered in the Services pane and to badge the Data Source References node, add an action to the Data Source References node and add a dialog to help guide a user to register the database connections needed.
Once the connections have been registered, the datasources can be registered in the project and server specific info added to the project (setup folder with connection pool configurations).

This feature will also be used by the  User settings migration feature</a> for 6.0

This feature is similar to the 5.5. There will be a new Services palette, but only database connections will be listed, not data sources. Data sources will have to be resolved project by project, same as 5.5. See <a href="http://www.netbeans.org/kb/55/vwp-migration.html">

Resolving a Data Source </a>Migrating a project can be defined as :

  • opening a Creator 2 or VWP 5.5 project
  • opening a VW 6 project on another computer which doesn't have the equivalent database driver and connections registered

This feature will perform the following:

  1. Listen for all projects opened in the IDE
  2. For each project, check if the project contains any datasources. If the project contains a datasource, retrieve the data sources from the project and check to see if connections for each data source have been registered.
  3. Check for an existing connection. If connection is missing then badge the Data Source Reference(s) node, post an Alert dialog and add a Resolve Data Source(s) action
  4. If a matching connection has been registered and the project's data sources have not been updated then the project's datasources will be automatically updated and a message is printed in the Output window, "Data Sources have been resolved"
  5. If connections and/or driver needed by the project have not been registered, the Project and Data Source References node will be badged and a Resolve Data Source(s) action will be added. Choosing this action will open a Resolve Data Source(s) dialog that lists the missing datasources.  When the user selects the action on the Project node, Resolve Data Source(s) clicks to Resolve then the Add Connection dialog opens where the user can register a driver and connection for the data source

Once the datasources have been resolved, remove the Resolve Data Source(s) context menu and print a message to the Output window to inform the user that the Data Sources have been resolved

More info
There will be child node under Data Source References, for each data source in the project, (see Travel child node in (figure 1) . The child data source node will not have an action.

Only those data sources which don't have a corresponding Database Connection will be listed in the Resolve Data Source(s) dialog. If a child data source node has a corresponding connection then it won't be badged.

For example, if the project has another data source, named Foo and there is a database connection for Foo in the Services tab then Foo will appear as a child of the Data Source References node, but it won't have a badge (red square in top right corner of the image). Also, Foo will not be listed in the Resolve Data Source(s) dialog.

Use cases

Use Case A. User has a project developed in Java Studio Creator 2 or VWP 5.5 that uses rowsets - pages with components bound to rowsets and wants to import this project in NetBeans 5.5.

Use Case B. User has developed a new Visual Web application that contains a rowsets.  If another user wants to use this project or the developer has removed the userdir then the data sources will not be found

Here's the steps required for both use cases to resolve missing data connections:

  1. Open the project
  2. If the project has data sources for which there is no corresponding database connection in the Runtime window, the Data Source References node icon will be badged (visible after expanding the project node). An alert dialog opens to inform the user that the project has errors and provides instructions on how to resolve the data source problem.


    (Figure 1)

  3. A context menuitem is added to the Project node, Resolve Database Problem. Selecting this context menuitem will open a dialog listing the missing data sources (for which there is no corresponding Database connection)
    Note: Figure 2 shows the action on the Data Source References node, where the action, Resolve Database Problem, is on the Project's node


    (figure 2)


    (figure 3)

  4. To resolve a database connection to another database server, select the datasource in the Resolve Datasource(s) dialog then click the Add Database Connection button and the Add Database Connection dialog will open.

    Figure 4
    (figure 4)

  5. If the driver has not been added then click the dropdown and choose New Driver, otherwise choose the appropriate driver.
  6. Fill in all fields. If any field is entered incorrectly, a connection error dialog will open
    # After clicking OK, a new JDBC Driver node is added to the Runtime|Databases|Drivers node (if it had not been previously registered)and a new connection is added to the Runtime|Databases|Connections node
    # If the page containing the components bound to rowset(s) is open, refreshing the page will restore the connections (or clicking the Continue button in the Component Error window)
  7. For databases used besides Java DB then JDBC drivers the user is required to manually copy the drivers to the Glassfish lib directory in order to execute the application
  8. If Glassfish is the target server, then this feature will add the server specific files to the project, if needed.

    As a result, the project's pages that have components that bind to rowsets will rebind successfully, automagically and the project can be deployed successfully.

    Gotchas

    If a user cleans up the App Server by deleting domain1 or removing connections then by choosing to Resolve Data Sources, the connection resources are added to the project so it can be deployed successfully.

Parameters for connecting to the Travel database

  • User ID = travel
  • Password = travel
  • Database URL = jdbc:derby://localhost:1527/travel 

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed