Database application development is a feature of JBuilder Professional and Enterprise. Distributed application development is a feature of JBuilder Enterprise.
You can use different Resolver implementations to save changes back to your data source. QueryDataSets
use a QueryResolver
to save changes by default. The default resolver can be overridden by setting the StorageDataSet.resolver
property. When data is provided to the data set, the StorageDataSet
tracks the row status
information (either deleted, inserted, or updated) for all rows. When data is resolved back to a data source like a SQL server, the row status information is used to determine which rows to add to, delete from, or modify in the SQL table. When a row has been successfully resolved, it obtains a new row status of resolved (either RowStatus.UPDATE_RESOLVED, RowStatus.DELETE_RESOLVED, or RowStatus.INSERT_RESOLVED). If the StorageDataSet
is
resolved again, previously resolved rows will be ignored, unless changes have been made subsequent to previous resolving.
This topic explores the basic resolver functionality provided by the DataExpress package. It extends the concepts explored in the "Querying a database" tutorial to the resolving phase where you save your changes back to the data source.
To step through this tutorial, use the files you created from the "Querying a database" tutorial, or start with the completed sample files, located in the /samples/DataExpress/QueryProvider directory.
The "Querying a database" tutorial explored the providing phase where data is obtained from a data source. The tutorial
instantiated a QueryDataSet
and associated UI components, and displayed the data retrieved from the JDataStore employee sample. The Save button on the JdbNavToolBar
can be used to save data changes back to the employee file.
In the next topic, we add a button that also performs basic resolving code. When either the custom button or the toolbar's Save button is pressed, the changes made to the data in the QueryDataSet
are saved to the employee data file using the QueryDataSet
's default QueryResolver
.
The source code for the completed tutorial is located in the /samples/DataExpress/QueryResolver directory of your JBuilder installation. The running application looks like this:
To create this application,
JButton
component from the Swing tab of the component palette. Set the button's text
property to Save Changes. (See the finished application at the beginning of this tutorial for general placement of the controls in the UI.)
JButton
is still selected, then click the Events tab of the Inspector. Select, then double-click the actionPerformed()
method. This changes the focus of the AppBrowser from the UI designer to the Source pane and displays the stub for the actionPerformed()
method.
Add the following code to the actionPerformed()
method:
try { database1.saveChanges(queryDataSet1); System.out.println("Save changes succeeded"); } catch (Exception ex) { // displays the exception on the JdbStatusLabel if the // application includes one, // or displays an error dialog if there isn't DBExceptionHandler.handleException(ex); }If you've used different names for the instances of the objects, for example, database1, replace them accordingly.
Run the application by selecting Run|Run Project. The application compiles and displays in a separate window. Data is displayed in a table, with a Save Changes button, the toolbar, and a status label that reports the current row position and row count.
If errors are found, an error pane appears that indicates the line(s) where errors are found. The code of the custom button is the most likely source of errors, so check that the code above is correctly entered. Make corrections to this and other areas as necessary to run the application.
When you run the application, notice the following behavior:
You can resize the window to display more fields, or scroll using the horizontal scroll bar.
Make changes to the data displayed in the table by inserting, deleting, and updating data. You can save the changes back to the server choosing either,
the Save button of the JdbNavToolBar
"Customizing the default resolver logic"