Jetspeed - DB Portlets
Now that Jetspeed is up and running it's time to see if I can create a portlet - esp if I can create one without writing any code. And sure enough, there is a DatabaseBrowserPortlet that can be "configured" - e.g. no code necessary to have very basic DBMS query capability.
So, how is this configuration actually done in a Jetspeed environment? There are two main pieces - setting up the datasource and configuring the portlet. And as always, there are fun configuration challenges ahead.
Datasource Configuration
Jetspeed uses Torque to handle connections to DBMS (I won't go into Pools, DataSources, or Connections - but there is a good Torque reference here). Thus, creating the connection is a matter of configuring Torque.properties.
The default configuration is set up to work with the included hypersonic DBMS, through the following parameters....
torque.database.default=default
torque.database.default.adapter=hypersonic
torque.dsfactory.default.connection.driver = org.hsqldb.jdbcDriver
torque.dsfactory.default.connection.url = jdbc:hsqldb:${webappRoot}/WEB-INF/db/jetspeed
torque.dsfactory.default.connection.user = sa
torque.dsfactory.default.connection.password =
torque.dsfactory.default.factory=org.apache.torque.dsfactory.TorqueDataSourceFactory
To make it work on my WebLogic 8.1/SQL Server 2000 setup (with the weblogic JDBC drivers), I had to change those settings to:
torque.database.default=default
torque.database.default.adapter=mysql
torque.dsfactory.default.connection.user = jmetro
torque.dsfactory.default.connection.password = jmetro
torque.dsfactory.default.connection.driver = weblogic.jdbc.sqlserver.SQLServerDriver
torque.dsfactory.default.connection.url = jdbc:bea:sqlserver://localhost:1433;DatabaseName=jmetro
torque.dsfactory.default.factory=org.apache.torque.dsfactory.TorqueDataSourceFactory
Now, in theory, I should have been able to ADD a new connection, rather than replace the existing one - but all my attempts to add a new connection of a different DBMS type have failed. To see how to add a new connection of the same DBMS type (e.g. two different SQL Server databases), see here.
Also, if you are going to use a different DBMS for "default", make sure that you have populated it correctly - there are two scripts to run as documented in the Jetspeed tutorial.
Configuring the Portlet
This is much simpler, at least when using the default database as described above. I changed my demo-portlets.xreg to have the following:
<portlet-entry name="DatabaseBrowserJMetro1" hidden="false" type="ref" parent="DatabaseBrowserPortlet" application="false">
<meta-info>
<title>DatabaseBrowserJMetro1</title>
<description>DB Portlet Example</description>
</meta-info>
<parameter name="template" value="database-browser-portlet" hidden="false"/>
<parameter name="customizeTemplate" value="database-browser-customize" hidden="false"/>
<parameter name="action" value="portlets.browser.DatabaseBrowserAction" hidden="false"/>
<parameter name="sql" value="select processDefId, processId, processName from AW_Process" hidden="false"/>
<!-- to use an alternate torque pool, set this parameter -->
<!--parameter name="poolname" value="jmetro" hidden="false"/ -->
<parameter name="windowSize" value="5" hidden="false"/>
<media-type ref="html"/>
</portlet-entry>
The interesting piece to me (at this basic stage) is the <param name="sql".../> entry in which you specify the query. There is the implication that an alternative torque pool can be used, but as mentioned above, I was unable to configure one of those, so I stuck with the default.
And amazingly enough - I have a simple database pluglet. I will work for a little while longer to see if I can figure out how to have connections to two different DBMS, I am sure there must be a way - as it would be quite common to have a portal that retrieved information from different places.