Global.helma.Database (driver, url, name, user, password)
Sourcecode in /home/hannes/helma/modules/helma/Database.js:
22:   helma.Database = function(driver, url, name, user, password) {
23:       if (!driver || !url || !name)
24:           throw("Insufficient arguments to create helma.db.Connection");
25:       if (typeof password != "string")
26:           password = "";
27:   
28:       var MYSQL = "mysql";
29:       var ORACLE = "oracle";
30:       var JDBC = "jdbc:";
31:      var DRIVER_MYSQL = "org.gjt.mm.mysql.Driver";
32:      var DRIVER_ORACLE = "oracle.jdbc.driver.OracleDriver";
33:  
34:      if (driver == MYSQL) {
35:          driver = DRIVER_MYSQL;
36:          if (url.indexOf(JDBC) != 0)
37:              url = "jdbc:mysql://" + url + "/" + name;
38:      } else if (driver == ORACLE) {
39:          driver = DRIVER_ORACLE;
40:          if (url.indexOf(JDBC) != 0)
41:              url = "jdbc:oracle:thin:@" + url + ":" + name;
42:      }
43:  
44:      var DbSource = Packages.helma.objectmodel.db.DbSource;
45:      var DatabaseObject = Packages.helma.scripting.rhino.extensions.DatabaseObject;
46:      var DbSource = Packages.helma.objectmodel.db.DbSource;
47:  
48:      var props = new Packages.helma.util.ResourceProperties();
49:      props.put(name + ".url", url);
50:      props.put(name + ".driver", driver);
51:      if (user) {
52:          props.put(name + ".user", user)
53:      }
54:      if (password) {
55:          props.put(name + ".password", password);
56:      }
57:      var source = new DbSource(name, props);
58:      var connection = source.getConnection();
59:  
60:      this.getConnection = function() {
61:          return connection;
62:      };
63:  
64:      this.getObject = function() {
65:          return new DatabaseObject(source);
66:      };
67:  
68:      this.getProductName = function() {
69:          return connection.getMetaData().getDatabaseProductName().toLowerCase();
70:      };
71:  
72:      this.isOracle = function() {
73:          return source.isOracle();
74:      };
75:  
76:      this.isMySql = function() {
77:          return this.getProductName() == MYSQL;
78:      };
79:  
80:      this.query = function(sql) {
81:          var statement = connection.createStatement();
82:          var resultSet = statement.executeQuery(sql);
83:          var metaData = resultSet.getMetaData();
84:          var max = metaData.getColumnCount();
85:          var result = [];
86:          while (resultSet.next()) {
87:              var row = {}
88:              for (var i=1; i<=max; i+=1)
89:                  row[metaData.getColumnName(i)] = resultSet.getString(i);
90:              result.push(row);
91:          }
92:          return result;
93:      };
94:  
95:      this.execute = function(sql) {
96:          var statement = connection.createStatement();
97:          return statement.execute(sql);
98:      };
99:  
100:      this.getName = function() {
101:          return source.getName();
102:      };
103:  
104:      this.getDriverName = function() {
105:          return source.getDriverName();
106:      };
107:  
108:      this.toString = function() {
109:          return "[helma.Database " + this.getName() + "]";
110:      };
111:  
112:      for (var i in this)
113:          this.dontEnum(i);
114:  
115:      return this;
116:  }