The DbSource is now retrieved from the application

as it should, instead of IServer.
This commit is contained in:
hns 2001-04-18 14:01:09 +00:00
parent 322c0b80ac
commit b9aefba787

View file

@ -20,7 +20,8 @@
package helma.framework.extensions; package helma.framework.extensions;
import helma.objectmodel.*; import helma.framework.core.Application;
import helma.objectmodel.DbSource;
import FESI.Parser.*; import FESI.Parser.*;
import FESI.AST.*; import FESI.AST.*;
import FESI.Interpreter.*; import FESI.Interpreter.*;
@ -59,13 +60,12 @@ class ESDatabase extends ESObject {
ESDatabase(ESObject prototype, ESDatabase(ESObject prototype,
Evaluator evaluator, Evaluator evaluator,
ESObject esRowSetPrototype, ESObject esRowSetPrototype,
String dbsource, int flag) { DbSource dbsource, int flag) {
super(prototype, evaluator); super(prototype, evaluator);
this.esRowSetPrototype = esRowSetPrototype; // specific to an evaluator this.esRowSetPrototype = esRowSetPrototype; // specific to an evaluator
try { try {
DbSource src = (DbSource) IServer.dbSources.get (dbsource.toLowerCase ()); connection = dbsource.getConnection ();
connection = src.getConnection (); driverName = dbsource.getDriverName ();
this.driverName = src.getDriverName ();
} catch (Exception e) { } catch (Exception e) {
// System.err.println("##Cannot find driver class: " + e); // System.err.println("##Cannot find driver class: " + e);
// e.printStackTrace(); // e.printStackTrace();
@ -717,11 +717,17 @@ public class Database extends Extension {
private transient Evaluator evaluator = null; private transient Evaluator evaluator = null;
private ESObject esDatabasePrototype = null; private ESObject esDatabasePrototype = null;
private ESObject esRowSetPrototype = null; private ESObject esRowSetPrototype = null;
Application app;
public Database () { public Database () {
super(); super();
} }
public void setApplication (Application app) {
this.app = app;
}
////////////////// Added by Hannes Wallnoefer ////////////////// Added by Hannes Wallnoefer
class GlobalGetDBConnection extends BuiltinFunctionObject { class GlobalGetDBConnection extends BuiltinFunctionObject {
GlobalGetDBConnection(String name, Evaluator evaluator, FunctionPrototype fp) { GlobalGetDBConnection(String name, Evaluator evaluator, FunctionPrototype fp) {
@ -731,8 +737,12 @@ public class Database extends Extension {
throws EcmaScriptException { throws EcmaScriptException {
if (arguments.length != 1) if (arguments.length != 1)
throw new EcmaScriptException ("Wrong number of arguments in getDBConnection(dbsource)"); throw new EcmaScriptException ("Wrong number of arguments in getDBConnection(dbsource)");
String srcname = arguments[0].toString ();
DbSource dbsrc = app.getDbSource (srcname.toLowerCase ());
if (dbsrc == null)
throw new EcmaScriptException ("DbSource "+srcname+" does not exist");
ESDatabase db = new ESDatabase (esDatabasePrototype, this.evaluator, ESDatabase db = new ESDatabase (esDatabasePrototype, this.evaluator,
esRowSetPrototype, arguments[0].toString(), 0); esRowSetPrototype, dbsrc, 0);
return db; return db;
} }
} }