Sunday Nov 26, 2006

Background


In Java Studio Creator 2, to connect a Creator 2 web application to a database, a data source must be created first using the Add Data Source feature in the Server Navigator. Visual Web Pack (VWP) also uses data sources, however, data sources are generated automatically and unfortunately, there is no convenient way to name or rename a data source. See Renaming a Data Source entry.

In VWP, data sources are generated when a database table is dragged and dropped onto a VWP Page or component in a VWP Page (e.g. Page1 that is created when creating a new Visual Web application)

The name of the data source is generated automatically. To see the name of the data source generated, in the Outline, expand the SessionBean (or the bean in which the database table was dropped) and select a rowset node.  Then check the Properties window for the data source property for the name.

Also, JDBC resources are created in the project under the setup folder. To view the resources for a project, with the project opened, switch to the Files tab and expand the setup folder then open the resources file. Resource files will have "extra properties" such as the connection info - username, driver name, database port number, etc.

The data source name must match the JNDI name created in the Application Server JDBC Resources, otherwise,
when executing an application an HTTP 500 error will occur.

A missing data connection means that the data source was not found in the IDE's context.xml and/or no NetBeans database connection and corresponding JDBC Driver reference exists.

Here, I'll describe how to import a project from Creator 2, another Visual Web Pack installation or restored the userdir. For users of the Technology Preview release, see the notes below. Also for more info,
there is a migration document available

VWP Final Release Information

Changes in the final release

  • There is a new Help topic for Data Source References. When the Data Source References node is selected, type the F1 key, or search Help
  • The project node is no longer badged and project name label does not change to red if there are
    unresolved data source references. This change helps some with open-project-performance

  • There is a new Data Source References node and a child node for each Data Source . Expand the project's node to view.

  • The Resolve Database Problems context menu has been replaced by Resolve Data Sources context menu located on the Data Source References node.

  • If a data source is missing then a badge is pinned to the node representing the data source that is missing

Importing a Creator 2 database project


1. User has a database project developed in Java Studio Creator 2 Update 1 and wants to import this project in VWP, or


2. User has developed a new Visual Web database application that contains a rowsets. (if another user wants to use this project or the developer has restored the userdir, then the data sources will not be found)


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

  • Open the project

  • (VWP Technology Preview Only)Project node icon will be badged, in the Projects window

  • missing_datasource_badge.GIF

  • Right-click and select Resolve Database Problem to open a dialog listing the missing database connection(s)

  • missing_datasources.GIF
  • By selecting a Data Source name then clicking the Add connection button, the Add Database Connection dialog will open. Note, a connection has been preconfigured for Java DB, presuming Glassfish has been registered and the IDE has been restarted. If the IDE was not restarted then the user is required to navigate to the location of derbyclient.jar (%GLASSFISH_INSTALL_PATH%\javadb\lib),select the jar and continue with the following steps

  • If the data source to resolve is to a Java DB database then fill in the username, password, JDBC URL and select a validation table.
  • example: parameters for connecting to the Travel database
    • User ID = travel

    • Password = travel

    • Database URL = jdbc:derby://localhost:1527/travel

  • Next, click the Add button and you're done

    add_connection_travel.GIF
  • To resolve a database connection to another database server, the user can either click the Edit New
    button or from the Server Type dropdown select item
    to add a new server type and make the driver jar available. This will open the Edit Database Server Types dialog

missing_database_type.GIF
  • Click the New button to locate the JDBC Driver jar file then click OK

  • This will return you to the Add Connection dialog

  • Fill in the name for the server type, such as the name of the database server plus the parameters for connecting to the desired database.

  • Lastly, click the Add button and you're done.

  • After a successful setup, a new Driver node is added to the Runtime|Databases|Drivers node and a new connection is added to the Runtime|Databases|Connections node

  • add_connection_travel.GIF
  • 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)

  • For databases used besides Java DB then JDBC drivers must be copied to the Glassfish lib directory in order to execute the application

  • If resources (JNDI/connection pool) haven't been generated on the App Server and JNDI resources have not been added to a project (in the setup folder)
  • Refresh action - new Context menu also on the Data Source References node. Choosing this action will check the status of the Data Sources in the project. This is useful if a Page hadn't been opened and data sources are missing then a badge will be added to the Data Source References node.

    3. A project is opened and data sources have not been created in the context. Choosing to Resolve Data Source(s) adds data sources to the context, plus connection resources. If another project that uses the same data source is opened then previously, then select the Data Source References node, right-click and choose Resolve Data Source(s) . After a few seconds the data sources will be resolved and the project can be deployed

    4. 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. After removing domain1 folder, use the command

    ant -f setup.xml
    to restore the user domain.

    Notes



    • Since Java DB is not bundled with VWP, when adding a new Connection, the user can navigate to the Derby installation diretory under Glassfish (javadb\lib) to add derbyclient.jar

    • Technology Preview Information

      Importing a Creator 2 database project


      1. User has a database project developed in Java Studio Creator 2 Update 1 and wants to import this project in VWP, or


      2. User has developed a new Visual Web database application that contains a rowsets. (if another user wants to use this project or the developer has restored the userdir, then the data connections will not be found)


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

      • Open the project

      • (VWP Technology Preview Only)Project node icon will be badged, in the Projects window

      • missing_datasource_badge.GIF
      • Right-click and select Resolve Database Problem to open a dialog listing the missing database connection(s)

      • missing_datasources.GIF
      • By selecting a Data Source name then clicking the Add connection button, the Add Database Connection dialog will open. Note, a connection has been preconfigured for Java DB, presuming Glassfish has been registered and the IDE has been restarted. If the IDE was not restarted then the user is required to navigate to the location of derbyclient.jar (%GLASSFISH_INSTALL_PATH%\javadb\lib),select the jar and continue with the following steps

      • If the data connection to resolve is to a Java DB database then fill in the username, password, JDBC URL and select a validation table.
      • example: parameters for connecting to the Travel database
        • User ID = travel

        • Password = travel

        • Database URL = jdbc:derby://localhost:1527/travel

      • Next, click the Add button and you're done

      add_connection_travel.GIF
    • To resolve a database connection to another database server, the user can either click the Edit New
      button or from the Server Type dropdown select item
      to add a new server type and make the driver jar available. This will open the Edit Database Server Types dialog

    missing_database_type.GIF
  • Click the New button to locate the JDBC Driver jar file then click OK

  • This will return you to the Add Connection dialog

  • Fill in the name for the server type, such as the name of the database server plus the parameters for connecting to the desired database.

  • Lastly, click the Add button and you're done.

  • After a successful setup, a new Driver node is added to the Runtime|Databases|Drivers node and a new connection is added to the Runtime|Databases|Connections node

  • add_connection_travel.GIF
  • 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)

  • For databases used besides Java DB then JDBC drivers must be copied to the Glassfish lib directory in order to execute the application

  • If resources (JNDI/connection pool) haven't been generated on the App Server and JNDI resources have not been added to a project (in the setup folder)
    3. A project is opened and data sources have not been created in the context. Choosing to Resolve Database Problems adds data sources to the context, plus connection resources. If another project that uses the same data source is opened then previously, Resolve Database Problems won't add the connection resources to the project (this is fixed in the Final Release) *
    4. If a user cleans up the App Server by deleting domain1 or removing connections then by choosing to Resolve Database Problems, the connection resources are added to the project so it can be deployed successfully. After removing domain1 folder, use the command
    ant -f setup.xml
    to restore the user domain.

    Notes



    • Since Java DB is not bundled with VWP, when adding a new Connection, the user can navigate to the Derby installation diretory under Glassfish (javadb\lib) to add derbyclient.jar

    • * Bug (this is fixed in the Final Release)- if more than one project is opened and they use the same data source then data sources can be resolved for only the first project.

      • To resolve data sources for each project


        1. Exit NetBeans

        2. Edit the context.xml file in the userdir (e.g. C:\Documents and Settings\< user >\.netbeans\5.5\context.xml and remove the entry surrounded by <object> </object> corresponding to the data source just added

        3. Restart NetBeans and then resolve the data sources for the other project






    Comments:

    It looks like in VWP I can't use a DataProvider without explicitly connecting a component to a DB table. I mean that I want to populate a table with data that is extracted from DB by DAO objects that I manage elsewhere. Unfortunately I can't add resource-ref to web.xml and sun-web.xml because they are wiped away each time I re-build. This happens, if I'm not mistaking what I'm reading in netbeans forums, because VWP is not aware of the data source, but it really doesn't help me. Is there a way to work around all this ?

    Posted by Pier on December 20, 2006 at 03:21 AM PST #

    The Table UI component can be bound to a Sun DataProvider, such as ObjectListDataProvider (OLDP). From the Palette, (Data Providers section near the bottom) drag and drop an ObjectListDataProvider to SessionBean1 in the Outline, not the Page. Next, in SessionBean1.java, you'll have to populate the OLDP. Fetch the data thru DAO and store in an object of type com.sun.rave.web.ui.model.Option[] Next, bind the Table UI component to the OLDP. You may have to save your project, close the project and reopen for the OLDP to appear - use the Table Layout customizer to do the binding - there is a dropdown in the customizer dialog. Note that OLDP is transactional, so you have to remember to commit changes to actually force the updates to occur.

    Posted by John Baker on December 20, 2006 at 10:04 PM PST #

    Here's some documentation on Data Providers: http://developers.sun.com/prodtech/javatools/jscreator/reference/docs/help/2update1/components/dataprovider_list.html http://developers.sun.com/prodtech/javatools/jscreator/reference/docs/apis/dataprovider/index.html Other API documentation: http://developers.sun.com/prodtech/javatools/jscreator/reference/docs/apis/index.jsp Mostly applicable to VWP except VWP with Java EE 5 projects uses JavaServer Faces 1.2.x

    Posted by 67.170.207.112 on December 20, 2006 at 10:12 PM PST #

    I'm a beginer and you your guide about how to solve the HTTP 500 is shallow. You are actually the only one who refers to this problem and i hoped you would be the one to help but you didn't. If you can provide more details it would be great - gbenshim@gmail.com is my e-mail and you would make my day if you reply with a helpful suggestion. Thanx :-)

    Posted by Gilad on February 25, 2007 at 09:34 AM PST #

    Thanks for this article. Hope VWP can catch up to fix the data source naming problem quickly. Generated data sources name are not the best way to handle. I also find your blog about renaming the data source. That was very useful and solve a specific problem as well. Thanks again.

    Posted by Win Pe on May 03, 2007 at 11:59 PM PDT #

    Post a Comment:
    • HTML Syntax: NOT allowed