| Last Updated: | August 10, 2003 |
| Status: | Production |
| Version: | PDK Release 2, (9.0.2 and later) |
The DBPreferenceStore sample provider illustrates the use of an alternative implementation of the PreferenceStore interface, DBPreferenceStore, to maintain portlet customization data in a relational database. In order for the DBPreferenceStore to be able to service multiple requests in parallel without suffering from performance overheads, it makes use of a pooled database connection provided by the J2EE server. This article describes how to configure your environment in order to run the sample, and should also be useful to anyone who plans to use DBPreferenceStore in portlets of their own.
This section describes how to create the table required by the DBPreferenceStore class.
cd d:\jpdk\doc\dbPreferenceStore
sqlplus scott/tiger@mydb
| Column Name |
XOPEN Datatype |
Length |
Mandatory |
In Primary Key? |
|---|---|---|---|---|
| REFERENCE_PATH | VARCHAR | 250 | Yes | Yes |
| PATH_TYPE | VARCHAR | 60 | Yes | Yes |
| SEARCH_PATH | VARCHAR | 250 | Yes | No |
| DATA_CLASS | VARCHAR | 250 | No | No |
| LONG_VALUE | LONGVARBINARY | No | No |
For best performance, you should also create indexes on the PATH_TYPE and SEARCH_PATH columns.
To quickly set up the JPDK_PREFERENCE_STORE2 table on an Oracle database, you simply need to run the jpdk_preference_store2.sql script by typing the following in sqlplus:
@jpdk_preference_store2
For non-Oracle databases, the second column in the table above gives the type for each database column using the XOPEN standard name used by JDBC (e.g. in java.sql.Types) to denote its datatype. Your database vendor may use different keywords to denote these types. For example, the Oracle JDBC drivers map VARCHAR to the VARCHAR2 Oracle type, and LONGVARBINARY to the LONG RAW Oracle type. Consult the documentation for your JDBC drivers to determine the correct type to use with your database.
You need to set up a data source for the pooled connection to the database account containing the JPDK_PREFERENCE_STORE2 table with the JNDI path jdbc/PooledConnection. On OC4J, this can be achieved by adding an entry such as the following to data-sources.xml in j2ee/home/config. You should edit the highlighted line so that it contains a valid JDBC URL to your database server. This should be of the form jdbc:oracle:thin:@<host name>:<port number>:<SID>. If you are not sure what the host name, port number and SID for your server are, you can use the Net8 Assistant to look up these settings.
| <data-source class="com.evermind.sql.DriverManagerDataSource" location="jdbc/UnPooledConnection" xa-location="jdbc/xa/XAConnection" ejb-location="jdbc/PooledConnection" connection-driver="oracle.jdbc.driver.OracleDriver" username="scott" password="tiger" url="jdbc:oracle:thin:@my.host.com:1521:orcl" inactivity-timeout="30" /> |
You should now be able to register the DBPreferenceStore sample provider on a portal using the service id urn:dbpref. Consult the PDK-Java Installation guide if you are unsure how to do this.
Once registered, try adding some of the provider's portlets to a page and then customizing those portlets, e.g. by editing the portlet's title. This time, any customizations you make will be stored in the table you configured in your database.
| Revision History: |
|
| Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065, USA http://www.oracle.com/ |
Worldwide Inquiries: 1-800-ORACLE1 Fax 650.506.7200 |
Copyright and Corporate Info |