You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Steven Noels <st...@outerthought.org> on 2003/08/20 09:05:00 UTC

Database.js

Hi peeps,

I'm messing around with the GetTogether registration page, which gives 
me a chance to test all this new wonderful Woody & flow stuff, but I'm 
stuck on the usage of Database.js. I'm not planning to use any O/R 
mapping, since I'll have two tables at most.

In PetStoreImpl.js, there's a code fragment that reads:

PetStore.prototype.getConnection = function(id) {
     if (true) {
         // temporary hack to avoid requiring datasource config in 
cocoon.xconf
         java.lang.Class.forName("org.hsqldb.jdbcDriver");
         var jdbc = 
java.sql.DriverManager.getConnection("jdbc:hsqldb:.", "sa", "")
         var conn = new Database(jdbc);
         if (this.hsql == null) {
             // keep hsql in-memory database alive
             this.hsql = 
java.sql.DriverManager.getConnection("jdbc:hsqldb:.", "sa", "");
         }
         return conn;
     } else {
         // lookup datasource in cocoon.xconf
         return Database.getConnection(id);
     }
}

but since I want to use my cocoon.xconf datasources config, I'm trying 
to set up a connection using:

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);

somewhere.

I'm greeted however with the interesting message: The undefined value 
has no properties. Has anyone already played with this? I'm looking for 
a snippet of sample code, without the weight that Petstore carries, to 
open a connection to a cocoon.xconf-defined pool.

Thanks,

</Steven>
-- 
Steven Noels                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at            http://blogs.cocoondev.org/stevenn/
stevenn at outerthought.org                stevenn at apache.org


Re: Database.js

Posted by Christopher Oliver <re...@verizon.net>.
Steven Noels wrote:

>
>
> ... so basically I have two possible outcomes of my try{} block, each 
> calling another pipeline. I'm worried that the flowscript only 
> executes upto that sendPage, never reaching the conn.close() in the 
> finally{} block. Or does it?
>
> </Steven>

No, you're fine because cocoon.sendPage() doesn't block. But it would be 
a problem if you called sendPageAndWait()


Re: Database.js

Posted by Steven Noels <st...@outerthought.org>.
Christopher Oliver wrote:

> I just checked in a fix for this. The problem was that it wasn't using FOM.

Looking good, thanks.

I have another question of connection handling and flowscript execution. 
My script currently looks like this:

function form(form) {

     var model = form.getModel();

     var formurl = cocoon.parameters["event-id"];

     pipeline = "registration/" + formurl + "/showform";

     form.show(pipeline, formHandler);

	var conn = getConnection("foo");
	
	try {
	
	    if (checkRecordInDatabase(model.email, conn) == true) {
	
	    	pipeline = "registration/" + formurl + "/duplicate";
	    	cocoon.sendPage(pipeline, {"email": model.email});
	
	    }
	    else {
	
		    var registration = new Registration(model.fname, model.lname,
		    	model.company, model.address, model.city, model.zip, model.country,
		    	model.tel, model.fax, model.email);
		    addRecord(registration, conn);
		
		   	pipeline = "registration/" + formurl + "/success";
	        cocoon.sendPage(pipeline, registration.asHashMap());
	
	   	}
	} finally {

	   	conn.close();
	    form.finish();
	}
}

... so basically I have two possible outcomes of my try{} block, each 
calling another pipeline. I'm worried that the flowscript only executes 
upto that sendPage, never reaching the conn.close() in the finally{} 
block. Or does it?

</Steven>
-- 
Steven Noels                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at            http://blogs.cocoondev.org/stevenn/
stevenn at outerthought.org                stevenn at apache.org


Re: Database.js

Posted by Christopher Oliver <re...@verizon.net>.
I just checked in a fix for this. The problem was that it wasn't using FOM.

Steven Noels wrote:

> Hi peeps,
>
> I'm messing around with the GetTogether registration page, which gives 
> me a chance to test all this new wonderful Woody & flow stuff, but I'm 
> stuck on the usage of Database.js. I'm not planning to use any O/R 
> mapping, since I'll have two tables at most.
>
> In PetStoreImpl.js, there's a code fragment that reads:
>
> PetStore.prototype.getConnection = function(id) {
>     if (true) {
>         // temporary hack to avoid requiring datasource config in 
> cocoon.xconf
>         java.lang.Class.forName("org.hsqldb.jdbcDriver");
>         var jdbc = 
> java.sql.DriverManager.getConnection("jdbc:hsqldb:.", "sa", "")
>         var conn = new Database(jdbc);
>         if (this.hsql == null) {
>             // keep hsql in-memory database alive
>             this.hsql = 
> java.sql.DriverManager.getConnection("jdbc:hsqldb:.", "sa", "");
>         }
>         return conn;
>     } else {
>         // lookup datasource in cocoon.xconf
>         return Database.getConnection(id);
>     }
> }
>
> but since I want to use my cocoon.xconf datasources config, I'm trying 
> to set up a connection using:
>
> 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);
>
> somewhere.
>
> I'm greeted however with the interesting message: The undefined value 
> has no properties. Has anyone already played with this? I'm looking 
> for a snippet of sample code, without the weight that Petstore 
> carries, to open a connection to a cocoon.xconf-defined pool.
>
> Thanks,
>
> </Steven>