用Java创建流水线SQL / NOSQL查询

时间:2012-03-01 08:40:38

标签: java apache-camel spring-integration

我正在尝试在Java中创建一个支持链式/流水线查询的框架,其中一个查询的输出将被转换为用作另一个查询的输入。像PyCascading之类的东西这些查询将在运行时进行。我查看了一些框架并发现Apache Camel &安培; Spring Integration因为它们提供了链接和路由(企业集成模式)的概念。我发现Apache Camel比Spring Integration(恕我直言)更好。


我应该为我的框架使用Apache Camel还是有更好的方法来实现这个目标?

我的查询语法将是

Query query1 = "select customer.id from customer where customer.name = 'ABC'";
Query query2 = "select account.id from account where account.custid in {$1}";
// $1 will be the input of second query
from(query1).inputto(query2).printOutput();

1 个答案:

答案 0 :(得分:1)

这可以使用camel-jdbc和一些基本的Camel功能(如simple)来允许您内联结果解析......

  

[CAMEL-JDBC]结果作为ArrayList [HashMap [String,Object]]在OUT体中返回   List对象包含行列表和Map   对象包含每个行,并使用String键作为列名。

然后可以使用此结果动态构建后续查询...

from("direct:start")
  .setBody(constant("select customer.id as ID from customer where customer.name = 'ABC'"))
  .to("jdbc:myDataSource")

  //now, use simple/ognl to extract the first result and the 'ID' from the Map in the body
  .setBody(simple("select account.id from account where account.custid in ${body[0][ID]}"))
  .to("jdbc:myDataSource")

  .log("ACCOUNT IDS = ${body}");