LINQ Tools for Java

LINQ Tools for Java

 

今天先介绍工具:

1、JoSQL        http://sourceforge.net/projects/josql/?source=navbar

JoSQL (Java Objects SQL) provides SQL capabilities for querying, ordering and grouping of collections of Java objects (POJOs). It allows a SQL statement to be applied to the collection of objects and the matching set returned, ordered and grouped.

官方介绍比较简单

可以参考官方manual:http://josql.sourceforge.net/manual/index.html

或者自己看源码。

2、Quaere        http://quaere.codehaus.org/Home

目前该项目没有发布版本,官方说法是由于需求变更导致。

Quaere is an open source, extensible framework that adds a querying syntax reminiscent of SQL to Java applications. Quaere allows you to filter, enumerate and create projections over a number of collections and other queryable resources using a common, expressive syntax.

Quaere detaches queries from the query API used by different queryable resources such as databases, catalogs and other structured data, allowing one language to be used to query numerous resources.

Quaere的语法比较简单:

public class GettingStartedWithQuaere {
    public static void main() {
        City[] cities=City.ALL_CITIES;

        Iterable<City> largePopulations =
            from("city").in(cities).
            orderBy("city.getName()").
            orderByDescending("city.getPopulation()").
            select("city");

        for (City city : largePopulations) {
            System.out.println(city);
        }
    }
}

 还可以和JPA结合:

SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
EntityManagerFactory entityManagerFactory = 
    new EntityManagerFactoryImpl(sessionFactory, PersistenceUnitTransactionType.RESOURCE_LOCAL, true);
QueryableEntityManager entityManager = 
    new QueryableEntityManager(entityManagerFactory.createEntityManager());

// Select all customers in the Washington region
Iterable<Customer> waCustomers =
        from("c").in(entityManager.entity(Customer.class)).
        where(eq("c.getRegion()", "WA")).
        select("c");

System.out.println("These customers are located in the Washington region:");
for (Customer c : waCustomers) {
    System.out.println(c.getCompanyName());
}

 是不是很方便。

可以从svn上直接拖代码下来自己研究。

3、linq4j    http://www.hydromatic.net/linq4j/

linq4j is a port of LINQ (Language-Integrated Query) to Java.

 

目前项目发布了一个快照版本,感兴趣的可以测试下,功能很强大。

 

 

你可能感兴趣的:(tools)