This PostgreSQL-based tutorial adapted from Estep's by: Jim Caley
Email: caley@chesco.com
My simple requirements, with the exception of the database type, were the same as Estep's:
My environment was as follows:
For more information on this patch take a look at the mailing list message from Ludovic Lange.
========== PATCH FOR DATABASE MANAGER / DODS ===========
Index:
modules/DatabaseManager/src/com/lutris/appserver/server/sql/CoreDO.java
===================================================================
RCS file:
/cvs/Enhydra/modules/DatabaseManager/src/com/lutris/ appserver/server/sql/CoreDO.java,vretrieving revision 1.13
diff -r1.13 CoreDO.java
125,126c125,126
< public static void setOIdColumnName(String oidColumnName) {
< oidColumnName = oidColumnName;
---
> public static void setOIdColumnName(String _oidColumnName) {
> oidColumnName = _oidColumnName;
141,142c141,142
< public static void setVersionColumnName(String versionColumnName) {
< versionColumnName = versionColumnName;
---
> public static void setVersionColumnName(String _versionColumnName) {
> versionColumnName = _versionColumnName;Index:
modules/DODS/src/com/lutris/dods/builder/ generator/query/templates/writeFileHeader.template
===================================================================
RCS file:
/cvs/Enhydra/modules/DODS/src/ com/lutris/dods/builder/generator/query/templates/writeFileHeader.template,vretrieving revision 1.3
diff -r1.3 writeFileHeader.template
125a126
> builder.setStringMatchDetails( "<STRING_MATCH>","<STRING_WILDCARD>" );
For Enhydra 2.3: Edit /usr/local/enhyra2.3/bin/multiserver , adding the following line just before the "Build up classpath." section (use the correct path for the location of your PostgreSQL JDBC driver):
DRIVER_CLASSES=/usr/lib/pgsql/jdbc6.5-1.2.jarand making the "Build up classpath." section look like this:
# # Build up classpath. #
if [ "X{CLASSPATH}" = "X" ] ; then CLASSPATH=${ENHYDRA_CLASSES}${PS}${DRIVER_CLASSES} else CLASSPATH=${ENHYDRA_CLASSES}${PS}${CLASSPATH}${PS}${DRIVER_CLASSES} fiFor Enhydra 3.0: Edit /usr/local/enhyra3.0/bin/multiserver , adding the following line just before the "Build up classpath." section (use the correct path for the location of your PostgreSQL JDBC driver):
DRIVER_CLASSES=/usr/lib/pgsql/jdbc6.5-1.2.jarand making the "Build up classpath." section look like this:
# # Build up classpath. # if [ "X${CLASSPATH}" = "X" ] ; then NEWCP=${ENHYDRA_CLASSES}${PS}${DRIVER_CLASSES} else NEWCP=${ENHYDRA_CLASSES}${PS}${CLASSPATH}${PS}${DRIVER_CLASSES} fi
cd /usr/prj
newapp simpledb
cd /usr/prj/simpledb make
cd /usr/prj/simpledb/output ./start
Load the following URL in your browser. Be patient, it takes a while (a minute or more) to load the page the first time.
http://localhost:9000/Welcome.po
Ctl-C
cd /usr/prj/simpledb/simpledb/presentationEdit Welcome.html
cd /usr/prj/simpledb make
cd /usr/prj/simpledb/output ./start
Load the following URL in your browser. Be patient, it takes a while (a minute or more) to load the page the first time.
http://localhost:9000/Welcome.poYou should see the line you typed in the HTML file at the bottom of the page.
Ctl-C
dods <enter>
Select the <root> package node in the lower left window Edit->Package Change name to "simpledb" no quotes <OK>
Select the <simpledb> package node in the lower left window Insert->Package Change Name field to "data" no quotes <OK>
Select the <data> package node in the lower left window Insert->Data Object Change Name field to "Person" no quotes Select Database Tab Change db Table Name field to "person" no quotes <OK>
Select <Person> Data Object Node in lower left window Insert->Attribute Change name field to "name" no quotes Click the Database tab and check "Can be queried" <OK>
Database->PostgreSQL
File->Save As Browse to /usr/prj/simpledb change the File name field to simpledb.doml NOTE: You must type the extension <Save>
File->Build All Browse to /usr/prj/simpledb/simpledb change the File name field to "data" no quotes <Re/Create Directory>
<Yes> Next you'll see a window that shows the build progress of the DODS output. <Close> when the last message is "DODS BUILD COMPLETE"
createdb simpledb
psql simpledb
simpledb= > \i /usr/prj/simpledb/simpledb/data/create_tables.sql
simpledb= > select * from person;should show:
name|objectid|objectversion ----+--------+------------- (0 rows)and:
simpledb= > select * from objectid;should show:
next ---- (0 rows)
simpledb=> INSERT INTO person (name, objectid, objectversion) simpledb-> VALUES ('simpledb works!', 1, 1); simpledb=> INSERT INTO objectid ( next ) VALUES ( '2' );
\q
package simpledb.presentation; import java.util.Date; import com.lutris.xml.xmlc.*; import com.lutris.appserver.server.httpPresentation.*; import simpledb.data.*; import com.lutris.dods.builder.generator.query.*; public class Welcome implements HttpPresentation { public void run(HttpPresentationComms comms) throws HttpPresentationException, NonUniqueQueryException, DataObjectException { String now = new Date().toString(); WelcomeHTML welcome = (WelcomeHTML)comms.xmlcFactory.create(WelcomeHTML.class); welcome.setTextTime(now); PersonDO person; PersonQuery pquery = new PersonQuery(); person = pquery.getNextDO(); welcome.setTextName( person.getName() ); comms.response.writeHTML(welcome); } }
Save the file
BEGIN_APPEND
#----------------------------------------------------------------------------- # Database Manager Configuration #----------------------------------------------------------------------------- # # The databases that are used by CSAM. Each of these databases # has configuration parameters set under DatabaseManager.DB."databaseName". # DatabaseManager.Databases[] = "simpledb"
# # The default database used in this application. # DatabaseManager.DefaultDatabase = "simpledb"
# # Turn on/off debugging for transactions or queries. Valid values # are "true" or "false". # DatabaseManager.Debug = "false"
# # The type of database. Normally this is "Standard". # DatabaseManager.DB.simpledb.ClassType = "PostgreSQL"
# # The jdbc driver to use. # Note that this changes to org.postgresql.Driver with PGSQL 7.0 # DatabaseManager.DB.simpledb.JdbcDriver = "postgresql.Driver"
# # Database url. # DatabaseManager.DB.simpledb.Connection.Url = "jdbc:postgresql:simpledb"
# # Database user name. All connections are allocated by this user. #
DatabaseManager.DB.simpledb.Connection.User = ""
# # Database user password. # DatabaseManager.DB.simpledb.Connection.Password = ""
# # The maximum number of connections that a connection # pool will hold. If set to zero, then connections # are allocated indefinitely or until the database # refuses to allocate any new connections. # DatabaseManager.DB.simpledb.Connection.MaxPoolSize = 30 # # Maximum amount of time that a thread will wait for # a connection from the connection pool before an # exception is thrown. This will prevent possible dead # locks. The time out is in milliseconds. If the # time out is <= zero, the allocation of connections # will wait indefinitely. # DatabaseManager.DB.simpledb.Connection.AllocationTimeout = 10000
# # Used to log database (SQL) activity. # DatabaseManager.DB.simpledb.Connection.Logging = false # # The number of object identifiers that are allocated # as a group and held in memory. These identifiers # are assigned to new data objects that are inserted # into the database. # DatabaseManager.DB.simpledb.ObjectId.CacheSize = 20 DatabaseManager.DB.simpledb.ObjectId.MinValue = 1
# # Following two lines must be added for PostgreSQL, # since oID can't be used for column name # DatabaseManager.ObjectIdColumnName = "ObjectId" DatabaseManager.VersionColumnName = "ObjectVersion" END_APPEND
Add your PostgreSQL JDBC driver into the CLASSPATH of your /usr/prj/simpledb/simpledb/start file by adding the following two lines before the multiserver line:
CLASSPATH=/usr/lib/pgsql/jdbc6.5-1.2.jar export CLASSPATHBe sure to use the correct path to your driver.
cd /usr/prj/simpledb make
cd output ./start
http://localhost:9000/Welcome.poYou should see the original text that mentioned it would be replaced when
DatabaseManager.Debug = "true" DatabaseManager.DB.simpledb.Connection.Logging = trueNote that for these to actually do anything you also need to add "DEBUG" to one or both of the following lines in /usr/prj/simpledb/simpledb/multiserver.conf.in, like so:
Server.LogToFile[] = EMERGENCY, ALERT, CRITICAL, ERROR, WARNING, INFO, DEBUG Server.LogToStderr[] = EMERGENCY, ALERT, CRITICAL, ERROR, WARNING, INFO, DEBUGBe sure to cd to /usr/prj/simpledb and run make again after changing these options!
/opt/enhydra3.0/bin/multiserver -nojit ./multiserver.conf
If you did all of the above right, you now have a simple Enhydra application on your hands that works with a database and DODS output which is integrated in a newapp generated application. Congrats!!!
G.W. & J.C.
Last revision: June 19, 2000