C H A P T E R 8 |
Tutorial--Section 2.2 Create the CustomerModel |
This chapter describes how to create a model to access the RDBMS in the Sun ONE Application Framework application.
1. Select the main module folder.
2. Click the Add Model button on the Sun ONE Application Framework toolbar.
The Select Model Type panel displays.
3. Enter CustomerModel in the Name field.
4. Select JDBC SQL Query Model from the model component list.
The list you see might vary depending on the Sun ONE Application Framework version and the possible addition of custom or third party component libraries.
The Select Datasource page displays.
6. Select jdbc/jdbc-pointbase from the combo box.
The Select Database Tables page displays.
The Select Table Columns page displays.
11. Click Add All to include all of the columns in your Model.
12. Click Finish to create the Model.
The CustomerModel object is created in the main module.
13. Expand the CustomerModel to see all of the columns.
14. Double-click the CustomerModel folder to view the code in the CustomerModel Java class.
1. Under the Columns node of the CustomerModel, select the CUSTOMER_TBL_CUSTOMER_NUM model field.
2. In the property sheet, select the Model Field Properties tab.
If the Properties tab is not visible, click the View -> Properties menu option, or right-click the key field column and select the Properties action.
3. Change the value of the Key Field property from false to true.
For servlet containers that do not support JNDI data sources, you can rely on explicit use of a JDBC driver.
Note - In section 2.1 of this tutorial (Task 1: Accessing a SQL Database), if you are testing your this application in a servlet container that does not support JNDI, you disabled the use of JNDI and declared the explicit use of the PointBase JDBC driver in the SQLConnectionManagerImpl class. |
If you are testing in a servlet container that does not support JNDI, you must set the connection username and password explicitly in the model so that a proper database connection can be created before the model is executed.
Note - For production environments, you should use JNDI connections. |
Add the bold code below to the CustomerModel's constructor.
public CustomerModel() { super(); setDefaultConnectionUser("pbpublic"); setDefaultConnectionPassword("pbpublic"); } |
While providing the datasource username and password as demonstrated above is not a good practice for a real world application, it is practical for this tutorial. Take extra care to obtain and provide the username and password in a more secure and robust implementation. When using the JNDI method, this code is unnecessary and this login information is provided by the configured JNDI connections in the application server.
Copyright © 2003, Sun Microsystems, Inc. All rights reserved.