You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Kelly <jo...@hotmail.com> on 2004/02/16 15:16:33 UTC

Database.js

Hi Steven,
                  I am also trying to use woody and flow but would like to use my cocoon.xconf datasource by setting up the connection:
cocoon.load("resource://org/apache/cocoon/components/flow/javascript/Database.js");

Registration.prototype.getConnection = function(id) {
	return Database.getConnection(id);
}

and:

var conn = this.getConnection(id);

I get a null pointer exception error.
I am also looking for a snippet of sample code
without the weight of the Petstore example to open a connection to cocoon.xconfig-defined pool.
Thanks,
Kelly

Re: Database.js

Posted by Steven Noels <st...@outerthought.org>.
On 16 Feb 2004, at 15:16, Kelly wrote:

> I am also looking for a snippet of sample code
> without the weight of the Petstore example to open a connection to  
> cocoon.xconfig-defined pool.

This is ancient, untested against current Cocoon HEAD, and code I wrote  
without people keeping my hands off the keyboard, so caveat emptor.

cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/ 
woody.js");
cocoon.load("resource://org/apache/cocoon/components/flow/javascript/ 
Database.js");

function form(form) {

     [...]

     var conn = getConnection("gt2003");

     try {

         if (checkRecordInDatabase(model.email, conn) == true) {

            var pipeline = "registration/" + eventid + "/duplicate";
            cocoon.sendPage(pipeline, {"email": model.email});

         }
         else {

             [...]

             addRecord(registration, conn);

             [...]

        }

     } finally {

         conn.close();

     }
}

[...]

function getConnection(id) {
   return Database.getConnection(id)
}

function addRecord(registration, conn) {

     var updatestmt = "INSERT INTO registration " +
         "(fname, lname, company, address, city, zip, country, tel, fax,  
email, eventid, hash, event6th, event7th) " +
         "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

     conn.update(updatestmt, registration.asInsertValues());

}

</Steven>
-- 
Steven Noels                            http://outerthought.org/
Outerthought - Open Source Java & XML            An Orixo Member
Read my weblog at            http://blogs.cocoondev.org/stevenn/
stevenn at outerthought.org                stevenn at apache.org