我们是否有一些IBM pureQuery的开源替代方案来查询Java Collection Framework或复合Java对象的内存中集合?
答案 0 :(得分:8)
正如我在评论中所提到的,我并不完全确定我理解你的问题:我不确定你是否在询问是否有替代pureQuery的OSS以及pureQuery是否适用于Java Collection Framework的内存中DS ,如果你想要一个可以在内存中集合上工作的OSS替代品,特别是Java Collections Framework。
但是,我会试一试......
如果您正在寻找一个用于与持久层进行查询库交互的开源软件,那么显而易见的解决方案非常简单:
请注意,这些也可用于内存数据库(如H2或HSQLDb)。
但是,如果要查询集合,则有一些项目,例如:
the java Query Language (JQL)语言扩展名:
ArrayList<String> words = dict.getWords(Puzzle.MEDIUM);
ArrayList<Integer> gaplengths = puzzle.getGapLengths();
List<Object[]> matches = selectAll(
String w : words,
Integer i : gaplengths | w.length() == i);
the Stack-Based Query Language for Java (sqbl4j)语言扩展名:
List<Product> products = getProductList();
List<Product> expensiveInStockProducts = #{
products
where unitsInStock > 0 and unitPrice > 3.00
};
List myObjs = getMyObjects ();
Query q = new Query ();
q.parse ("SELECT * FROM java.io.File WHERE name LIKE '%.java'");
QueryResults qr = q.execute (myObjs);
List res = qr.getResults ();
jxpath,对于使用XPath表达式的其他方法:
Address address = (Address)JXPathContext
.newContext(vendor)
.getValue("locations[address/zipCode='90210']/address");
Java的函数式编程库提供了类似的功能,因为它们使您可以访问基本的功能结构filter
,map
,collect
,transform
等......例如,用:
Set<String> strings = buildSetStrings();
Collection<String> filteredStrings =
Collections2.filter(strings, Predicates.containsPattern("^J"));
Array<Integer> a = array(97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42);
final Array<Integer> b = a.filter(even);
// with normal interfaces:
List<Person> buyersSortedByAges = sort(
extract(
select(sales, having(on(Sale.class).getValue(), greaterThan(50000)))
), on(Sale.class).getBuyer()
), on(Person.class).getAge());
// with fluent/chainable intefaces:
List<Person> buyersSortedByAges = with(sales)
.retain(having(on(Sale.class).getValue(), greaterThan(50000)))
.extract(on(Sale.class).getBuyer())
.sort(on(Person.class).getAge());
或许您只是在querying in-memory collections with pureQuery上寻找本教程?
答案 1 :(得分:2)
还支持索引和查询的CQEngine:CQEngine。
有关更多背景,请参阅类似问题:How do you query object collections in Java (Criteria/SQL-like)?