2011-03-23 77 views

回答

1

我不知道它会有足够的帮助,但是,正如你所要求的utils,我建议你阅读关于QUERY OBJECT PATTERN (P of EAA, M. Fowler),如果你有时间去实现一些东西,那么它是一个好的开始,否则你可能会寻找任何东西ORM框架。

+0

你知道任何框架,这可以帮助设计子查询和连接? 例如:选择* from person where id =(select * from map where id = 223) – Phani 2011-03-23 05:35:02

2

QueryDsl自动从您的Hibernate,JPA或JDO类创建查询对象,也可以from your DB schema

与Querydsl SQL查询是 这样简单:

QCustomer customer = new QCustomer("c"); 

SQLTemplates dialect = new HSQLDBTemplates(); // SQL-dialect 
SQLQuery query = new SQLQueryImpl(connection, dialect); 
List<String> lastNames = query.from(customer) 
    .where(customer.firstName.eq("Bob")) 
    .list(customer.lastName); 

它还supports subqueries

要创建创建 SQLSubQuery实例的子查询,定义查询 参数通过from,where等,并使用 唯一或列表来创建子查询 这是针对查询的一种类型安全的Querydsl 表达式。唯一的是 用于唯一的(单个)结果, 列表用于列表结果。

query.from(customer).where(
    customer.status.eq(
     new SQLSubQuery().from(customer2).unique(customer2.status.max())) 
    .list(customer.all()) 

query.from(customer).where( 
    customer.status.in(new SQLSubQuery().from(status).where(
    status.level.lt(3)).list(status.id)) 
    .list(customer.all())