LINQ for Java: Quaere

Discussions

News: LINQ for Java: Quaere

  1. LINQ for Java: Quaere (11 messages)

    Dion Almaer: he met the author of Quaere, which is an implementation of LINQ for Java. It's functional; the MS examples work; it's a way of representing iterable data in a relational format, more or less. Interesting stuff. From the introduction:
    Examples To import the DSL into any Java class, simply add the following import to the class: import static org.quaere.DSL.*; Below is an example of a simple query that selects the numbers less than five from an array of integers:Integer[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; Iterable lowNums = from("n").in(numbers) .where(lt("n", 5)) .select("n");This query uses a projection expression to select the names of all products in the array: List products = Arrays.asList(Product.getAllProducts()); Iterable productNames = from("p") .in(products) .select("p.getProductName()");The following query creates a sequence anonymous class instances with two properties containing the upper and lower case versions of the words in an array. The classes in the upperLowerWords collection will have two strongly typed JavaBean properties:String[] words = {"aPPLE", "BlUeBeRrY", "cHeRry"}; Iterable upperLowerWords = from("w") .in(words) .select( create( property("upper", "w.toUpperCase()"), property("lower", "w.toLowerCase()") ) );
    This is a great example of a DSL implemented with Java - and entirely usable from standard Java code. Do you think you'd find a good use for it in your code? Of course, on the subject of DSLs, Ola Bini weighs in with Concurrent DSLs:
    With all the current talk of DSLs and concurrency, what I find lacking is discussions about how to combine the two. Of course, domain specific languages are incredibly important - they create a logical separation between the implementors of the business logic, and the people implementing the actual implementation of the DSL. Does it seem like a strange idea to want many DSLs to be able to run parallel to each other? I would imagine that in most cases a DSL that describes business rules and business logic is sequential in the particulars, but that there are also larger concurrency possibilities. This should be totally invisible for the business rule implementor in most cases - the runtime system should be able to run everything as efficient as possible.

    Threaded Messages (11)

  2. Nice![ Go to top ]

    A full LINQ-clone requires closures and support for inspecting the full expression tree at runtime. Otherwise we cannot get rid of those fragile, annoying string expressions...
  3. Its an Awesome news to hear LINQ coming to Java. Although "I'm working on LINQ" sounds cool "I'm working on Quaere" - I'm so sorry, why don't you call in sick?
  4. Groovy equivalent[ Go to top ]

    Here's the equivalent in Groovy: Integer[] numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] def lowNums = numbers.findAll { it < 5 } List products = Arrays.asList(Product.getAllProducts()) def productNames = products.collect { it.productName } String[] words = ["aPPLE", "BlUeBeRrY", "cHeRry"]; def upperLowerWords = words.collect { def val = new Expando() val.upper = it.toUpperCase() val.lower = it.toLowerCase() val } If you ask me it's much easier to read, even compared to the .NET LINQ where they have closures.
  5. Considered response[ Go to top ]

    It seems to me that LINQ has three major points that make it a useful technology, the first two being in common with SQL as well: 1) Separation of concern between the definition of the data request and its use. 2) Separation of concern between the definition of the data request and its implementation. 3) Integration of the definition of the data request into the 3GL being used to handle the results of the query. Now the example given here is a well-worn idea and is nothing new. It is constructing an expression tree using java methods and a standard Java API. So there is no language-level integration. This only affects point 3 partially. The other two points are still perfectly valid but pose the following obvious questions: a) The result is an Iterable. What happens if you want to be able to move back and forth in the list? b) The Iterable is untyped, what happens with type-safety? (this is related to point 3). c) When is the query plan created and when is it executed? On the initial call to the Iterable? How is the implementation chosen? One of the main reasons to push LINQ as a concept more is that we can move away from SQL only as a functional query language and have other types of data stores and have query engines that take advantage of the multi-core/massively parallel nature of the newer technologies. Can it do that? How can you set options to control this sort of query generation? Not knowing anything more, this seems enough to get the ball rolling. Michael
  6. Re: Considered response[ Go to top ]

    Answers to you questions can be found in this blog post: http://andersnoras.com/blogs/anoras/archive/2007/09/13/answering-questions-about-quaere.aspx Cheers, Anders Norås
  7. Saffron[ Go to top ]

    http://perforce.eigenbase.org:8080/@md=d&cd=//open/saffron/doc/&c=5tJ@//open/saffron/doc/index.html
  8. Right Mark. Mondrian rocks too. It's also in that server and John contributes to it and yes Saffron pre-dates LINQ. Not really new technology.
  9. joSQL[ Go to top ]

    Better/worse/same as joSQL? http://josql.sourceforge.net/ doing chained api calls seems more obfuscated than josql, and not necessarily faster/more compact theoretically. I haven't seen LINQ syntax other than "it's SQL for code", so maybe it's just matching the LINQ style in CSharpPokeInMyEye.
  10. Re: joSQL[ Go to top ]

    Hi Carl. First of all, JoSQL is a great framework that has brought many vitalizing ideas on working with POJOs. To clarify some of the confusion between Quaere and similar frameworks I've written a comparison of JoSQL and Quaere that shows some of the similarities and differences between the two. You'll find it one my here: http://andersnoras.com/blogs/anoras/archive/2007/09/18/what-s-the-difference-between-josql-quaere.aspx Regards, Anders Norås
  11. Quaere: alternative syntax[ Go to top ]

    What do you think about this: String[] cities = new String[]{"Auckland", "Oslo"}; Alias city = alias(cities); List places = from(city) .where(city.length().isBigger(5)) .orderBy(city.desc()) .select(city); Customer c = db.alias(Customer.class); List list = db.from(c) .where(c.city.is("London")) .orderBy(c.name.asc(), c.city.desc()) .select(); public class Customer { public Column id; public Column name; public Column city; } Plain old Java classes can be supported as well: Customer c = db.alias(Customer.class); List list = db.from(c) .where(equal(c.city, "London")) .orderBy(c.name, desc(c.id)) .select(); public class Customer { public Integer id; public String name; public String city; } Soon to be available...
  12. Saw it at JavaZone 2007[ Go to top ]

    ... in Oslo. Looked very interesting. What the presenter/author said was that LINQ in C# was implemented by having the compiler synthesize use of underlying classes etc. (I guess it's akin to how use of the "delegate" keyword is turned into a System.Delegate object for instance.) Perhaps the open-sourcing of Java will lead to something like "compiler plugins" that could support inline languages of the LINQ type, without having to resort to "tricks" like static import and Hibernate-like method chaining.