我设计了一个数据层 API 来使用 trireme-jdbc 建立 openge 数据库连接。当我使用cygwin通过trireme命令运行文件时,代码运行良好,但是当我使用命令'a127 project start'通过apigeetool启动整个项目时,它会引发一些关于trireme的错误。我已经使用 generic-pool 包与 trireme-jdbc 一起用于数据库连接池。下面是运行我的 trireme 但不是由 a127 运行的文件。这是一个 apigee API,因此文件夹结构完全符合 apigee 标准,这里也使用了 swagger。
var a127 = require('a127-magic');
var express = require('express');
var Pool = require('generic-pool').Pool;
var jdbc = require('trireme-jdbc');
var app = express();
module.exports = app; // for testing
// initialize a127 framework
a127.init(function(config) {
// include a127 middleware
app.use(a127.middleware(config));
var pool = new Pool(
{
name : 'Suppllier Collaboration - @Anil',
create : function(callback) {
var connOpenedge = new jdbc.Database(
{
url : 'jdbc:datadirect:openedge://serverhost:portno;DatabaseName=xxxxx',
properties : {
user : 'db_user',
password : 'db_password',
},
});
callback(null, connOpenedge);
},
destroy : function(client) {
client.end();
},
max : 10,
min : 2,
idleTimeoutMillis : 30,
log : true
});
// error handler to emit errors as a json string
app.use(function(err, req, res, next) {
console.log('we are just enter in app.js file');
if (typeof err !== 'object') {
// If the object is not an Error, create a representation that appears to be
err = {
message: String(err) // Coerce to string
};
} else {
// Ensure that err.message is enumerable (It is not by default)
Object.defineProperty(err, 'message', { enumerable: true });
}
// Return a JSON representation of #/definitions/ErrorResponse
res.set('Content-Type', 'application/json');
res.end(JSON.stringify(err));
});
pool.acquire(function(err, conn) {
if (err) {
throw err;
} else {
app.get("/getData", function(req, res) {
conn.execute('select * from "po" where "po-num" = ? and "vend-num" = ? ',
[4322452, 4301170 ], function(err, result, rows) {
if (err)
res.json("Sorry !Error to get data from symix....");
else
res.json(rows);
});
});
}
});
var ip = process.env.IP || 'localhost';
var port = process.env.PORT || 10010;
// begin listening for client requests
app.listen(port, ip);
console.log('we are inside app.js file');
console.log('try this:\ncurl http://' + ip + ':' + port + '/hello?name=Scott');
});